【发布时间】:2017-07-27 15:41:42
【问题描述】:
我经常写一个 Console.WriteLine 语句,然后在以后修改它。然后我会得到这样的陈述。
Console.WriteLine("{2} is not greater than {0} or smaller than {1}",min,max, grade);
有没有办法明确命名传递给 Console.WriteLine 的参数,这样我就不需要按顺序传递 min、max 和grade?p>
作为相关说明,我经常删除要在 Console.WriteLine 中打印的变量,如下所示,其中 {2} 已被删除。
Console.WriteLine("{3} is not greater than {0} or smaller than {1}",min,max, grade);
有没有办法不更改编号并说:
Console.WriteLine("{3} is not greater than {0} or smaller than {1}",{0}:min,{1}:max, {3}: grade);
类似于这样的陈述
@Html.ActionLink("Your profile", "Index", "Manage", routeValues: null, htmlAttributes: new { title = "Manage" });
【问题讨论】:
-
使用 C# 6 字符串插值:
$"{grade} is not greater...". -
为什么不使用字符串插值? $"{grade} 不大于 {min} 或小于 {max}"
-
请注意,字符串中没有自动完成。
标签: c# console.writeline