是否可以向字符串格式说明符中添加一些描述性文本?字符串格式描述文本
实施例:
string.Format ("{0:ForeName} is not at home", person.ForeName);
在该示例ForeName
被添加作为说明。
上面的语法显然是不正确的,但只是为了显示这个想法。
我问其原因,是因为在我的情况的字符串是在资源文件中,所以在资源文件中,您目前只能看到
{0} is not at home
在某些情况下,这是很难
上把握上下文{0}
是。
编辑:
在C#6串插与$
运营商已经出台,所以string.Format
不需要了:
$"{person.ForeName} is not at home";
您希望正在阅读代码的开发人员知道“{0}”中发生了什么,就是这样吗?一种评论? – Johnny5
这里有什么意图? – crush
只是谷歌“字符串格式命名参数”。没有原生的方法,只有解决方法。 http://stackoverflow.com/questions/159017/named-string-formatting-in-c-sharp –