Alternatives to " " for creating strings containing multiple whitespace characters

Viewed 76737

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't help but feel that this is somewhat reminiscent of using "" instead of String.Empty.

What can I use to create spaces that isn't " "?

13 Answers

You may create class extensions.

public static class StringExtensions
    {
        public static string GetSpace(this String)
        {
           return " ";
        }
    }

and you can call this.

String.GetSPace();

I tend to use string.Empty.PadLeft(8) for example

Related