Extension methods can be used to extend the set of methods that you can use for LINQ queries,
namespace TestConsoleApplication
{
class Program
{
static void Main(string[] args)
{
int[] myNumbers = { 1, 2, 3, 4, 5,7 };
// the j=>j lambda expression as a parameter to the method so compiler
// implicitly converts its value to double.
var avgQuery = myNumbers.MyCustomAverage(j => j);
Console.WriteLine(“My Average %=” + avgQuery);
}
}
//LINQ extension class
public static class MyLINQExtension
{
//This method takes – Func delegate as a parameter. This delegate // takes an object of generic type T and returns an object of type double.
public static double MyCustomAverage(this IEnumerable numbers, Func selector)
{
return ((from i in numbers select selector(i)).Average()/100);
}
}
}