我有一个项目,我不能使用System.Linq
,所以我正在尝试创建一个切割方法,其工作方式与linq完全相同,我该怎么做?自定义方法
var x = y.ToList().Where(t => t.Title != "Foo");
SOLUTION 1
protected void Page_Load(object sender, EventArgs e)
{
var x = y.ToList().Where<Microsoft.SharePoint.Navigation.SPNavigationNode>(x => x.Title != "Foo");
}
public static class Extensions
{
public static IEnumerable<T> Where<T>(this IEnumerable<T> source, Func<T, bool> filter)
{
foreach (var item in source)
{
if (filter(item))
yield return item;
}
}
}
注:.NET 2.0版
http://codeblog.jonskeet.uk/category/edulinq/ –
你有什么试过的? [源代码](http://referencesource.microsoft.com/#System.Core/System/Linq/Enumerable.cs)可能是一个很好的开始的地方 – Sayse
在Where之前没有ToList的要点。 – Andrew