(input parameters) => expression
() => SomeMethod()
(input parameters) => {statement;}
|
delegate int del(int i);
static void Main(string[] args)
{
del myDelegate = x => x * x;
int j = myDelegate(5); //j = 25
}
|
using System.Linq.Expressions;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Expression<del> myET = x => x * x;
}
}
}
|
public delegate TResult Func<TArg0, TResult>(TArg0 arg0)
Func<int, bool> myFunc = x => x == 5;
bool result = myFunc(4);
int[] numbers = { 5, 4, 1, 3, 9, 8, 6, 7, 2, 0 };
int oddNumbers = numbers.Count(n => n % 2 == 1);
var firstSmallNumbers = numbers.TakeWhile((n, index) => n >= index);
|