GetEnumerator使用
internal class Program
{
static async Task Main(string[] args)
{
var list = new List
{
1, 2, 3, 4, 5, 6, 7,
};
var res = Pairwise<int, string>(list, (s1, s2) =>
{
return $"{s1}:{s2}";
});
foreach (var item in res)
{
Console.WriteLine(item);
}
}
public static IEnumerable
{
using var e = source.GetEnumerator();
if (!e.MoveNext()) yield break;
var previous = e.Current;
while (e.MoveNext())
{
yield return resultSelector(previous, e.Current);
previous = e.Current;
}
}
}
输出


浙公网安备 33010602011771号