Tutorial by Examples

Full expressions can also be used in interpolated strings. var StrWithMathExpression = $"1 + 2 = {1 + 2}"; // -> "1 + 2 = 3" string world = "world"; var StrWithFunctionCall = $"Hello, {world.ToUpper()}!"; // -> "Hello, WORLD!" Live Demo...
var date = new DateTime(2015, 11, 11); var str = $"It's {date:MMMM d, yyyy}, make a wish!"; System.Console.WriteLine(str); You can also use the DateTime.ToString method to format the DateTime object. This will produce the same output as the code above. var date = new DateTime(2015, 1...
var name = "World"; var str = $"Hello, {name}!"; //str now contains: "Hello, World!"; Behind the scenes Internally this $"Hello, {name}!" Will be compiled to something like this: string.Format("Hello, {0}!", name);
String can be formatted to accept a padding parameter that will specify how many character positions the inserted string will use : ${value, padding} NOTE: Positive padding values indicate left padding and negative padding values indicate right padding. Left Padding A left padding of 5 (a...
You can use a colon and the standard numeric format syntax to control how numbers are formatted. var decimalValue = 120.5; var asCurrency = $"It costs {decimalValue:C}"; // String value is "It costs $120.50" (depending on your local currency settings) var withThreeDecimal...

Page 1 of 1