VS 中 C# 开发语法糖 发表于 2021-09-18 更新于 2023-07-06 分类于 Develop , DotNET 本文字数: 345 阅读时长 ≈ 1 分钟 在进行C#开发的过程中,有一些语法糖,可以提升开发体验和提高代码阅读性,特作此总结。 弃用 out 值 如果一个方法有多个 out 参数,当在使用时,不需要某些参数时,可以使用 out _ 进行占位放弃。示例: 12345678910111213141516// 定义public static bool IsRebar(Element ele,out string reason,out double diameter){ ...实现代码}// 使用public static void Test(){ Element ele; // 第一个 reason 不需要,所以使用 out _ 来占位,表示弃用 If(IsRebar(ele,out _,out double diameter)) { ... }}