Paolo Tedesco Paolo Tedesco - 1 year ago 99
C# Question

c#: difference between "System.Object" and "object"

In C#, is there any difference between using

in code rather than just
, or
rather than
and so on? Or is it just a matter of style?

Is there a reason why one form is preferrable to the other?

Answer Source

string is an alias for global::System.String. It's simply syntactic sugar. The two are exactly interchangable, and there'll be no difference in the compiled code.

Personally I use the aliases for variable names etc, but I use the CLR type names for names in APIs, for example:

public int ReadInt32() // Good, language-neutral

public int ReadInt() // Bad, assumes C# meaning of "int"

(Note that the return type isn't really a name - it's encoded as a type in the metadata, so there's no confusion there.)

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download