C#中{0}\{1}的含义

Lea*_*Asp 2 c#

{0}\{1}在c#中是什么意思,它返回一些字符串,但是以哪种格式和什么样的字符串?

Hab*_*bib 8

这意味着它期望参数被替换为字符串.就像是.

string.Format("{0}{1}","parameter1","parameter2");
Run Code Online (Sandbox Code Playgroud)

您可能会看到:复合格式

复合格式字符串和对象列表用作支持复合格式设置功能的方法的参数.复合格式字符串由零个或多个固定文本运行与一个或多个格式项混合组成.固定文本是您选择的任何字符串,每个格式项对应于列表中的对象或盒装结构.复合格式化功能返回一个新的结果字符串,其中每个格式项都由列表中相应对象的字符串表示替换.


Clo*_*ble 7

这些是字符串格式函数中通常使用的参数/参数:

DateTime dat = new DateTime(2012, 1, 17, 9, 30, 0); 
string city = "Chicago";
int temp = -16;
string output = String.Format("At {0} in {1}, the temperature was {2} degrees.",
                              dat, city, temp);
Console.WriteLine(output);
// The example displays the following output: 
//    At 1/17/2012 9:30:00 AM in Chicago, the temperature was -16 degrees.  
Run Code Online (Sandbox Code Playgroud)

请参阅文档