my_note - 日理万妓 2023-10-09 11:56 52阅读 0赞 1.C# $ 内插字符串 Console.WriteLine($"The value of pi is {Math.PI}"); 替代string.format 2. switch 的新写法 colorBand 是枚举 public static RGBColor FromRainbow(Rainbow colorBand) => colorBand switch { Rainbow.Red => new RGBColor(0xFF, 0x00, 0x00), Rainbow.Orange => new RGBColor(0xFF, 0x7F, 0x00), Rainbow.Yellow => new RGBColor(0xFF, 0xFF, 0x00), Rainbow.Green => new RGBColor(0x00, 0xFF, 0x00), Rainbow.Blue => new RGBColor(0x00, 0x00, 0xFF), Rainbow.Indigo => new RGBColor(0x4B, 0x00, 0x82), Rainbow.Violet => new RGBColor(0x94, 0x00, 0xD3), _ => throw new ArgumentException(message: "invalid enum value", paramName: nameof(colorBand)), }; public static decimal ComputeSalesTax(Address location, decimal salePrice) => location switch { { State: "WA" } => salePrice * 0.06M, { State: "MN" } => salePrice * 0.75M, { State: "MI" } => salePrice * 0.05M, // other cases removed for brevity... _ => 0M }; //属性模式 List<modelTest> list = new List<modelTest>(); list.Add(new modelTest {id=1, name="aaa", address="aaaaaa" }); list.Add(new modelTest { id = 2, name = "bbb", address = "bbbbbb" }); list.Add(new modelTest { id = 3, name = "ccc", address = "cccccc" }); list.Add(new modelTest { id = 4, name = "ddd", address = "dddddd" }); list.Add(new modelTest { id = 5, name = "eee", address = "eeeeee" }); var aa= list.Where(x=>x.name== "aaa").ToList(); var bb = list.Where(x => x.name == "bbbb"); var dd = list.Where(x => x.name == "bbbb").ToList();不会报错 不为null 但是count为0 var eecc = list.Where(x => x.name == "bbbb").First(); 序列为空 报错 var eecctt = list.Where(x => x.name == "bbbb").ToList().First(); 序列为空 报错 var dddddd = list.Where(x => x.name == "bbbb").FirstOrDefault(); 不会报错 为空 返回null var ccc= ""; 转载于:https://www.cnblogs.com/muxueyuan/p/11338520.html
相关 功夫不负有心人的mynote 今天的功夫不负有心人的mynote,我高兴得一蹦三尺高,这下,胡老师告诉我这次唱歌比赛得了第三名,你一定会听见更多的声音,草地又归于静寂,美丽的游 水深无声/ 2021年12月22日 04:19/ 0 赞/ 118 阅读
还没有评论,来说两句吧...