您的位置:首页 > 其它

Interpolated Strings

2015-11-17 10:49 169 查看
https://msdn.microsoft.com/en-us/library/dn961160.aspx

int apples = 4;
// Before C# 6.0
System.Console.WriteLine(String.Format("I have {0} apples", apples));
// C# 6.0
System.Console.WriteLine($"I have {apples} apples");


var result = string.Format("{0}{1}{2}{3}", tempChannelId, tempIndex, tempType, tempDeviceId);

升级为

var result = $"{tempChannelId}{tempIndex}{tempType}{tempDeviceId}";

优越性在于,不需要考虑{0}{1}{2}{3}和后面的变量的顺序对应
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: