https://www.youtube.com/watch?v=FupRSJe-cc0&list=PL90AF0EFFEF782D27&index=6
の6:00あたりで紹介されている。
独自の.Whereを実装できるようだ。
sample.cs
using System;
using System.Linq;
static class MainClass
{
static IEnumerable<int> Where(
this int[] ints, Func<int, bool> gauntlet)
{
Console.WriteLine("My Where()");
foreach(int i in ints)
if (gauntlet(i))
yield return i;
}
static void Main()
{
int[] numbers = new [] {3,1,4,1,5,9,2};
var result =
numbers
.Where(n => n < 3)
.Select(n => n);
foreach(int idx in result)
Console.WriteLine(idx);
}
}
結果
My Where()
1
1
2
Enumerable.Where()と記載の場合は独自の実装が使われない、というようなことを言っていた(多分)。
yield return i;
の理解はまだ。