What is the difference between String.Format and string.Format (and other static members of primitive data types)?
There's no difference, these are type aliases in C# for .Net framework types, you're calling the same method underneath.
For example:
int
is an alias forSystem.Int32
string
is an alias forSystem.String
You can find a complete list of these aliases on MSDN here.
Those are not related primitive data types. They are simply shorthands available in C#. string
aliases System.String
and int
aliases System.Int32
. Calls to int.MaxValue
are calls to Int32.MaxValue
. C# just allows you to type it in shorthand similar to what you would type if you were in another C-like language.
Most of the answers have it in general. HOWEVER, there are some cases in which the alias is required. Off the top of my head:
public enum MyEnum:Byte {...} //will not compile
public enum MyEnum:byte {...} //correct
There are a couple other places where you must use the alias; besides that, it's mostly style. The following two rules are generally accepted, perhaps the first more than the second:
- Use the alias (lowercase keyword) for all usages of that define a variable or member type (declaration, parameters, casting, generic type closure)
- Use the type name (PascalCased class identifier) for all usages of the type in static context (Calling static methods such as parsers or string manipulation methods, or static properties like MinValue/MaxValue).