C#中:可以用来代替用的String.Format数字标签?可以用、标签、数字、来代替

由网友(初醒)分享简介:。参见此链接http://msdn.microsoft.com/en-us/library/b1csw23d.aspx它似乎是不可能的String.Format方法使用标签,而不是指数在格式字符串参数有一些语法或功能,原产于.Net框架,允许使用的标签,而不是0,1,...,N?作为一个例子,怎么能这样:Console...

。参见此链接

http://msdn.microsoft.com/en-us/library/b1csw23d.aspx

它似乎是不可能的String.Format方法使用标签,而不是指数在格式字符串参数

有一些语法或功能,原产于.Net框架,允许使用的标签,而不是0,1,...,N?

作为一个例子,怎么能这样:

  Console.WriteLine(的String.Format({0} {1} {0} {1},富,酒吧));
 

变成是这样的:

  Console.WriteLine(的String.Format({FOO} {栏} {FOO} {}吧,
                                新{FOO =富,巴=酒吧}));
 
为什么要用内插字符串代替string.format

解决方案

有趣的问题 开反射后

心不是一个办法:

它计算在数字只有:

Refering to this link

http://msdn.microsoft.com/en-us/library/b1csw23d.aspx

it seems that it is not possible with the String.Format method to use labels instead of indices in the format string parameter.

Is there some syntax or functionality native to the .Net Framework that allows using labels instead of 0,1,...,N ?

As an example, how can this:

Console.WriteLine(String.Format("{0}{1}{0}{1}", "foo", "bar"));

become something like this:

Console.WriteLine(String.Format("{foo}{bar}{foo}{bar}", 
                                new { foo = "foo", bar = "bar" }));

解决方案

nice question after opening reflector

there isnt a way :

it counts in digits only :

阅读全文

相关推荐

最新文章