I\'m reading the Pro MVC 2 book, and there is an example of creating an extension method for the HtmlHelper class.
Here the code example:
public stat
I have implemented a where() extension method using Func please have a look...
public static IEnumerable Where ( this IEnumerable a , Func Method )
{
foreach ( var data in a )
{
//If the lambda Expression(delegate) returns "true" Then return the Data. (use 'yield' for deferred return)
if ( Method.Invoke ( data ) )
{
yield return data;
}
}
}
You can use it like,
foreach ( var item in Emps.Where ( e => e.Name == "Shiv" ).Select ( e1 => e1.Name ) )
{
Console.WriteLine ( item );
}