0100110010101
0100110010101

Reputation: 6729

String.Format against string.Format. Any issues?

Is there any performance differences between string.Format and String.Format ? As far as i understand string is a shortcut for System.String and there's no difference between them. Am i right?

Thanks!

Upvotes: 4

Views: 354

Answers (5)

Matt Howells
Matt Howells

Reputation: 41266

In C#, string is simply an alias for the CLR type System.String, so there is no performance difference. It is not clear why MS decided to include this alias, particularly as the other aliased types (int, long, etc.) are value types rather than reference types.

In my team we decided that static methods of the string class should be referenced as e.g. String.ToUpper() rather than string.ToUpper(), in order to be more consistent with other CLR languages.

Ultimately which version you use is up to you but you should decide which you will use in what context in order to improve consistency.

Upvotes: 2

Anton Gogolev
Anton Gogolev

Reputation: 115751

Yes, there's absolutely no difference from CLR's point of view: string vs String is purely C# syntactic sugar.

Upvotes: 1

VolkerK
VolkerK

Reputation: 96159

Yes, string is an alias for System.String in C#
Test it yourself:

    public static void Main(string[] args)
    {
        string s1 = "abc";
        System.String s2 = "xyz";
        Type t1 = s1.GetType();
        Type t2 = s2.GetType();

        System.Console.WriteLine( t1.Equals(t2) );
        return ;
    }

Upvotes: 1

Mark
Mark

Reputation: 2432

string and String both resolve to System.String. So no there is no difference at all.

Upvotes: 3

Philippe Leybaert
Philippe Leybaert

Reputation: 171784

Those are exactly the same. "string" is just an alias for "System.String" in C#

Upvotes: 13

Related Questions