C#6.0 $字符串插值

编程中经常用到字符串的拼接。
C#6.0之前的方法:

var plne=new Plane(){Category = Category.Bomber,Name = "B-1",State = State.Unknown};
var sb=new StringBuilder();
sb.Append(string.Format("Category={0},Name={1},State={2}",plan.Category,plane.Name,plane.State);

C#6.0之后的方法:

var p=new Plane(){Category = Category.Bomber,Name = "B-1",State = State.Unknown};
var sb=new StringBuilder();
sb.Append($"Category={p.Category},Name={p.Name},State={p.State}");

你可能感兴趣的:(C#,版本新特性)