c# string formatting

前端 未结 13 1531
离开以前
离开以前 2020-12-25 14:12

I m curious why would i use string formatting while i can use concatenation such as

Console.WriteLine(\"Hello {0} !\", name);

Console.WriteLine(\"Hello \"+          


        
13条回答
  •  清酒与你
    2020-12-25 14:26

    You are using a trivial example where there is not much of a difference. However, if you have a long string with many parameters it is much nicer to be able to use a format string instead of many, many + signs and line breaks.

    It also allows you to format numerical data as you wish, i.e., currency, dates, etc.

提交回复
热议问题