【发布时间】:2016-06-11 23:26:40
【问题描述】:
我有一个正在使用 c# 进行的迷你项目。我对 c# 还很陌生,想知道为什么我应该使用占位符 {0} 而不是 +。有什么不同吗?使用其中一个有什么好处?
这是一个例子-
public void DisplayMessage()
{
Console.WriteLine("Student Name:"+ Name); // Why not this
Console.WriteLine("Studnt Age: {0}", Age);// instead of this?
}
谢谢
【问题讨论】:
-
我看到你不是在尝试微优化,只是好奇。 Here 是你喜欢的东西。
-
在 C#6 中你也可以添加
Console.WriteLine($"Student Age: {Age}"); -
复杂的格式、多个字段和字符串格式的调整更容易
-
@displayName 好的,所以我从中得到的是,这真的没关系吗?
标签: c# methods placeholder