Interpolated Strings

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}和后面的变量的顺序对应

 

posted @ 2015-11-17 10:49  ChuckLu  阅读(307)  评论(0)    收藏  举报