内插字符串$与复合格式设置{}

Posted uftwkb24

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了内插字符串$与复合格式设置{}相关的知识,希望对你有一定的参考价值。

string name = "Mark";

var date = DateTime.Now;

复合格式设置{}:

// Composite formatting: Console.WriteLine("Hello, {0}! Today is {1}, it‘s {2:HH:mm} now.", name, date.DayOfWeek, date);

内插字符串$:

// String interpolation: Console.WriteLine($"Hello, {name}! Today is {date.DayOfWeek}, it‘s {date:HH:mm} now.");

// Both calls produce the same output that is similar to:

// Hello, Mark! Today is Wednesday, it‘s 19:40 now.

以上是关于内插字符串$与复合格式设置{}的主要内容,如果未能解决你的问题,请参考以下文章