the situation I'm in is following:
I have an interpolated string looking like this:
DateTime DateOfSmth;
string PlaceOfSmth;
$"{DateOfSmth}, {PlaceOfSmth}".Trim(' ',',');
And a format that should be used on it in:
string Format = "{0:dd.MM.yyyy}";
Now I'd like to use the format in the property Format
in the interpolated string, but I don't know how.
I.E: i'd like something like this to be the result:
$"{DateOfSmth:Format}, {PlaceOfSmth}".Trim(' ',',');
Could someone help?
Try this:
string format = "dd.MM.yyyy";
Console.WriteLine($"{DateOfSmth.ToString(format)}");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With