我所处的情况如下:
我有一个内插字符串,如下所示:
DateTime DateOfSmth;
string PlaceOfSmth;
$"{DateOfSmth}, {PlaceOfSmth}".Trim(' ',',');
以及应在以下格式中使用的格式:
string Format = "{0:dd.MM.yyyy}";
现在,我想在插值字符串的属性
Format
中使用格式,但是我不知道如何使用。I.E:我想要这样的结果:
$"{DateOfSmth:Format}, {PlaceOfSmth}".Trim(' ',',');
有人可以帮忙吗?
最佳答案
试试这个:
string format = "dd.MM.yyyy";
Console.WriteLine($"{DateOfSmth.ToString(format)}");
关于c# - 使用属性中的格式字符串,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/36175543/