22
1
using System;
2
3
public class Program
4
{
5
public static void Main()
6
{
7
double price = 12.456;
8
string name = "Lorem Ipsum";
9
DateTime paidOn = new DateTime(2018, 1, 1, 12, 34, 56);
10
11
// instead of doing this
12
string normal = name + " paid " + price.ToString("0.00") + " on " + paidOn.ToString("yyyy-MM-dd HH:mm:ss");
13
14
// you can do this
15
string interpolated = $"{name} paid {price:0.00} on {paidOn:yyyy-MM-dd HH:mm:ss}";
16
17
Console.WriteLine(normal);
18
Console.WriteLine(interpolated);
19
20
// 00.00 -> numbers are formatted into 2 decimal places, padded with zeros
21
}
22
}
Cached Result