Search This Blog

Friday, December 5, 2014

Func C# Example

C# System Func

Func is a parameterized type. 

  • accepts any number and kinds of input parameters
  • one type of the return value T
  • stores anonymous methods 
Example

1. Func<T, TResult>


Func<int, int> power = p => p * p;
int[] numbers = { 1, 2, 3 };
IEnumerable<int> powers = numbers.Select(power);
foreach (int p in powers)
     Console.WriteLine(p);