Edge cases in the string vs. String comparison in C#

Whilst most C# devel­op­er would know that in C# the string type is equiv­a­lent to the System.String type because string is sim­ply an alias for the System.String type. There are oth­er frame­work defined alias like string, such as int for System.Int32 and long for System.Int64.

Whilst in nor­mal usage the two are iden­ti­cal, thanks to Marc Gravell’s answer here, I found out about two inter­est­ing edge cas­es:

  • you need a  using Sys­tem; to use String, you don’t for string
  • if you define a local class String { }, then String refers to that class, you can’t define a class called string

On a relat­ed top­ic, one thing that’s always been curi­ous to me is that there are no ToInt or ToLong meth­ods in the Con­vert class but only ToIn32 and ToInt64. Dan Puzey gave me a plau­si­ble expla­na­tion for this though:

Con­vert is a frame­work class, not a lan­guage key­word. If it had meth­ods named after the C# key­words, the meth­ods would make no sense in VB or F# or oth­er .NET lan­guages.