using System.Collections.Generic;
delegate int MathOperation(int x, int y);
MathOperation add = (a, b) => a + b;
Console.WriteLine($"加法结果:{add(3, 5)}");
Action greet = () => Console.WriteLine("\n你好,世界!");
Func<int, int, string> compare = (x, y) =>
x > y ? $"{x} 大于 {y}" : $"{x} 不大于 {y}";
Console.WriteLine(compare(7, 5));
List<int> numbers = new List<int> { 2, 5, 8, 13, 21 };
var squared = numbers.Select(n => n * n);
Console.WriteLine("\n平方数:" + string.Join(", ", squared));
var evens = numbers.Where(num =>
bool isEven = num % 2 == 0;
Console.WriteLine("偶数:" + string.Join(", ", evens));
var button = new Button();
button.Click += (sender, e) =>
Console.WriteLine("\n按钮被点击!时间:" + DateTime.Now);
System.Threading.Tasks.Task.Run(async () =>
await System.Threading.Tasks.Task.Delay(500);
Console.WriteLine("\n异步操作完成!");
Func<int, int> multiplier = n => n * factor;
Console.WriteLine($"\n乘数结果:{multiplier(5)}");
public event EventHandler Click;
public void SimulateClick()
Click?.Invoke(this, EventArgs.Empty);