Skip to content

Commit

Permalink
Merge branch 'main' of github.com:luoyunchong/FreeKit
Browse files Browse the repository at this point in the history
  • Loading branch information
luoyunchong committed Oct 14, 2023
2 parents 03fb02d + 3a0cfb3 commit 35a4295
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/IGeekFan.FreeKit.Extras/Extensions/EnumerableExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace IGeekFan.FreeKit.Extras.Extensions;

/// <summary>
/// IEnumerable 扩展
/// </summary>
public static class EnumerableExtensions
{
public static IEnumerable<(T item, int index)> LoopIndex<T>(this IEnumerable<T> self) =>
self.Select((item, index) => (item, index));
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using IGeekFan.FreeKit.Extras.Extensions;
using Xunit;
using Xunit.Abstractions;

namespace IGeekFan.FreeKit.xUnit.Extras.Extensions;

public class EnumerableExtensionsTest
{
private readonly ITestOutputHelper _testOutputHelper;

public EnumerableExtensionsTest(ITestOutputHelper testOutputHelper)
{
_testOutputHelper = testOutputHelper;
}

[Fact]
public void LoopIndexTest()
{
// Create a list with integer values
List<int> myValues = new List<int>()
{
23, 34, 45, 56, 67
};

// Loop through the list and its index using an item/index tuple
foreach (var (item, index) in myValues.LoopIndex())
{
_testOutputHelper.WriteLine($"{index}: {item}");
}
}
}
1 change: 1 addition & 0 deletions test/IGeekFan.FreeKit.xUnit/IGeekFan.FreeKit.xUnit.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,5 @@
</None>
</ItemGroup>


</Project>

0 comments on commit 35a4295

Please sign in to comment.