How can I type “{0}” more quickly in Visual Studio?

前端 未结 2 829
伪装坚强ぢ
伪装坚强ぢ 2021-01-29 13:58

In C#, it\'s common to have to type {0}, {1}, etc. when formatting strings with string.Format() or Console.WriteLine(). Considering its frequency, it\'

2条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-01-29 14:38

    One of the benefits from string interpolation in C#6.0, which I find helps.

    Instead of:

    string s = String.Format("{0} and {1}", variable1, variable2);
    

    You can do:

    string s = $"{variable1} and {variable2}";
    

    See a guide: http://www.informit.com/articles/article.aspx?p=2422807

提交回复
热议问题