C# lambda表達式
using System;
using System.Linq;
using System.Reflection;
using System.Collections.Generic;
namespace Lambda表達式
{
class Program
{
static void Main(string[] args)
{
Func<int, int> square = x => x * x;
Console.WriteLine(10);
int[] numbers = { 1, 2, 3, 4, 5, 6 };
var squareNumbers = numbers.Select(x => x * x);
Console.WriteLine(string.Join(" ", squareNumbers));
Action<string> greet = name =>
{
string greeting = "Hello";
Console.WriteLine($"{greeting},{name}");
};
greet("World!");
Console.ReadKey();
}
}
}
參考