Alternatives to “ ” for creating strings containing multiple whitespace characters

后端 未结 12 1402
粉色の甜心
粉色の甜心 2020-12-09 15:30

I\'m wondering if there\'s a more OO way of creating spaces in C#.

Literally Space Code!

I currently have tabs += new String(\" \"); and I can\'

12条回答
  •  执念已碎
    2020-12-09 16:31

    Now that you've clarified in comments:

    In my actual code I'm doing new String(' ',numberOfSpaces) so I probably need to still use the new String part.

    ... the other answers so far are effectively useless :(

    You could write:

    const char Space = ' ';
    

    then use

    new string(Space, numberOfSpaces)
    

    but I don't see any benefit of that over

    new string(' ', numberOfSpaces)
    

提交回复
热议问题