C#String.Format参数 [英] C# String.Format args
本文介绍了C#String.Format参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个像这样的数组:
I have an array like this:
object[] args
,并且需要在字符串中插入这些args,例如:
and need to insert those args in a string, for example:
str = String.Format("Her name is {0} and she's {1} years old", args);
代替:
str = String.Format("Her name is {0} and she's {1} years old", args[0], args[1]);
注意:实际上第一行代码起作用了!但是args [1]丢失了!对不起,谢谢你.每个积分:)
NOTE: Actually the first line of code worked! But args[1] was missing! Sorry and thank you. Points for every one :)
推荐答案
如果数组args中至少有两个对象,则第一个示例应该可以正常工作.
Your first example should work fine, provided there are at least two objects in the array args.
object[] args = new object[] { "Alice", 2 };
str = String.Format("Her name is {0} and she's {1} years old", args);
这篇关于C#String.Format参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文