Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

which version of C# to use $ instead of string.format

I find a piece of code like this

int a = 100;
string str = $"{a:0.00}";
Console.WriteLine(str);

the result is "100.00"

The $ have the same function of string.Format, and I want to know which version of C#.

like image 451
Jerry Chou Avatar asked Dec 19 '22 19:12

Jerry Chou


1 Answers

This is called string interpolation, and it's part of C# 6, which was released in July as part of Visual Studio 2015.

like image 137
Joel Coehoorn Avatar answered Jan 06 '23 01:01

Joel Coehoorn