c# - Custom where method -
i have project can't use system.linq
, trying create cutsom method works same linq, how can that?
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; } } }
note : .net v 2.0
here's extension method:
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; } }
Comments
Post a Comment