なるほどねー C#3.0 (そのさん) の続き。
拡張メソッドによるLINQはnamespace System.Linq、
アセンブリ: System.Core で提供されています。
実装上はstaticクラスのstaticメソッドでしかないんだから、
C++/CLIから呼べるハズ。 れっつとらい。
using namespace System;
using namespace System::Collections::Generic;
using namespace System::Linq;
int main() {
List<int> il(gcnew array<int> { 1, 2, 3, 4, 5 });
// 偶数に対してtrueを返す
struct predicate {
static bool even(int n) { return n % 2 == 0; }
};
// 条件を満たすもんだけ抽出する
for each ( int n in Enumerable::Where(%il, gcnew
Func<int,bool>(&predicate::even)) ) {
Console::WriteLine(n);
}
return 0;
}
できちゃったー♪
ますますもって匿名delegateが羨ましくなりますです。