C# Func 和 Action
public class Tests { [Test] public void Test2() { DateTime startDate = new DateTime(2022, 10, 1, 0, 0, 0); DateTime endDate = startDate.AddMonths(1).AddSeconds(-1); var v = Environment.Version; var s1 = new Sword2() { Damage = 10000, Durability = 10000 }; var s2 = s1 with { Damage = 10001 }; var s3 = new Sword2() { Damage = 10000, Durability = 10000 }; Sword s4 = new(100, 100); if (s1.Aggressivity is null or { Length: 0 }) { Console.WriteLine($"{nameof(s1.Aggressivity)} is IsNullOrEmpty"); } if (s1.Aggressivity is not null and { Length: > 0 }) { if (s1.Aggressivity[0] is (>= 'a' and <= 'z') or (>= 'A' and <= 'Z') or '.') { } } switch (s1.Damage) { case >= 0 and < 100: break; case >= 100 and < 1000: break; case >= 1000 and < 100001: break; } Expression<Func<int, bool>> expression1 = static i => i > 1; Func<string, string> exp = (x) => x; var result = exp("Hello world"); Func<int, int, int> exp1 = (x, y) => x * y; var result1 = exp1(0, 1); result1 = exp1(1, 10); Action<int, int, List<int>> exp2 = (x, y, z) => { z.Add(x + y); }; var list = new List<int>(); exp2(1, 2, list); } record class Sword(int Damage, int Durability); record class Sword2 { public int Damage { get; set; } public int Durability { get; set; } public string Aggressivity { get; set; } } }
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· 三行代码完成国际化适配,妙~啊~
· .NET Core 中如何实现缓存的预热?
· 如何调用 DeepSeek 的自然语言处理 API 接口并集成到在线客服系统