VS2015 新特性_字符串拼接

1.使用變量

Customer customer =new Customer();

customer.FirstName="Jack";

customer.LastName="Smith";


舊版:string a =String.Format("FirstName is  {0},LastName is {1}.", customer.FirstName , customer.LastName);


新版:string a =String.Format("FirstName is \ {customer.FirstName} , LastName is  \ {customer.LastName}");


2.時間

string time =String.Format("{0:yyyy-MM-dd}",DateTime.Now);

string time=$"{DateTime.Now:yyyy-MM-dd}";


3.$

   string s1 = $"{name},{age}";
    string s2 = $"姓名={name},年齡={age}";

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章