Hi.
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!
Hi.
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!
Those are exactly the same. "string" is just an alias for "System.String" in C#
string and String both resolve to System.String. So no there is no difference at all.
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 ;
}
Yes, there's absolutely no difference from CLR's point of view: string
vs String
is purely C# syntactic sugar.
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.