C#中:可以用来代替用的String.Format数字标签? [英] C#: can labels be used instead of numbers with String.Format?

查看:151
本文介绍了C#中:可以用来代替用的String.Format数字标签?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

。参见此链接

<一个href="http://msdn.microsoft.com/en-us/library/b1csw23d.aspx">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 =富,巴=酒吧}));
 

解决方案

有趣的问题 开反射后

心不是一个办法:

它计算在数字只有:

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 :

这篇关于C#中:可以用来代替用的String.Format数字标签?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆