c# string formatting

前端 未结 13 1532
离开以前
离开以前 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:34

    I think a good example is about i18n and l10n

    If you have to change a string between different languages, this: "bla "+variable+"bla bla.." Will give problems to a program used to create sobstitution for your strings if you use a different language

    while in this way: "bla {0} blabla" is easily convertible (you will get {0} as part of the string)

提交回复
热议问题