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

Popular posts from this blog

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -