在字符串前加$相当于对string.format()的简化
如:
int m_a = 1;
int m_b = 2;
使用string.format():
Console.WriteLine(string.format("this is a:{0},this is b:{1}"),m_a,m_b));
使用了$,就可以在原来占位符的地方直接用参数代替
Console.WriteLine($"this is a:{m_a} ,this is b:{m_b}");
本文介绍在C#中使用$符号简化string.format()的方法,通过实例展示如何在字符串前加$来直接引用变量,提高代码的可读性和编写效率。
在字符串前加$相当于对string.format()的简化
如:
int m_a = 1;
int m_b = 2;
使用string.format():
Console.WriteLine(string.format("this is a:{0},this is b:{1}"),m_a,m_b));
使用了$,就可以在原来占位符的地方直接用参数代替
Console.WriteLine($"this is a:{m_a} ,this is b:{m_b}");

被折叠的 条评论
为什么被折叠?