What's the difference between string and System.String?

What's the difference between string and System.String?

Rate This
  • Comments 12

C# defines a number of aliases for CLR types. They may be used interchangably, and even mixed together, e.g.

string x = new System.String(' ', 5);.

These are the aliases defined:

Alias CLR type
string System.String
sbyte System.SByte
byte System.Byte
short System.Int16
ushort System.UInt16
int System.Int32
uint System.UInt32
long System.Int64
ulong System.UInt64
char System.Char
float System.Single
double System.Double
bool System.Boolean
decimal System.Decimal

[Author: Jon Skeet]

Leave a Comment
  • Please add 8 and 3 and type the answer here:
  • Post
  • Are these aliases just like aliasing a type in the using statement?

    So in effect, I could create my own aliases that match VB.NET data types?

    using Byte = System.Byte
    using Short = System.Int16;
    using Integer = System.Int32;
    using Long = System.Int64;

    Not saying that I would want to, but hey you could, right? :p
  • I think that void is also System.Void, but it is not interchable in C#, isn't it?

  • bool System.Boolean
  • String s;
    DateTime dt;

    if (dt == null) // error, because DateTime is value type
    if (s == null) // ok (because reference type?)
    Response.Write(dt); // writes "01.01.0001 00:00:00"
    Response.Write(s); // writes "", although s=null, why?
  • PingBack from http://sharpcode.com.br/blogs/rafaelsilva/archive/2008/08/28/afinal-qual-a-diferen-231-a-de-string-e-string.aspx

  • Here is a post which explains the difference between a bool and a boolean


    Hope you find it useful.

  • DateTIme is a Struct!! (value type)... String is a Sealed Class, so you can use as a Object ;)

  • what is the differences between a string and a language?

  • string is like an alias/shorthand for System.String. Similarly, int is an alias/shosthand for System.Int16.


  • @williams Alkali: the same difference as the difference between a spoon and a matchbox :P

  • There is no such difference between string and String (Syetem.String). The "string" keyword is an alias for System.String in the .NET Framework.


  • using is a "special" construct to handle automatic disposal of objects that implement the IDisposable interface;


    using (DataTable myTable = new DataTable("MyTable"))


    // do something with myTable

    myTable.Columns.Add(new DataColumn("Test", "".GetType()));


    The actual IL code generated courtesy of IlSpy goes like this:

    .method private hidebysig

    instance void DisposeTest () cil managed


    // Method begins at RVA 0x36f0

    // Code size 55 (0x37)

    .maxstack 4

    .locals init (

    [0] class [System.Data]System.Data.DataTable myDataTable


    IL_0000: ldstr "MyTable"

    IL_0005: newobj instance void [System.Data]System.Data.DataTable::.ctor(string)

    IL_000a: stloc.0



    IL_000b: ldloc.0

    IL_000c: callvirt instance class [System.Data]System.Data.DataColumnCollection [System.Data]System.Data.DataTable::get_Columns()

    IL_0011: ldstr "Test"

    IL_0016: ldstr ""

    IL_001b: callvirt instance class [mscorlib]System.Type [mscorlib]System.Object::GetType()

    IL_0020: newobj instance void [System.Data]System.Data.DataColumn::.ctor(string, class [mscorlib]System.Type)

    IL_0025: callvirt instance void [System.Data]System.Data.DataColumnCollection::Add(class [System.Data]System.Data.DataColumn)

    IL_002a: leave.s IL_0036

    } // end .try



    IL_002c: ldloc.0

    IL_002d: brfalse.s IL_0035

    IL_002f: ldloc.0

    IL_0030: callvirt instance void [mscorlib]System.IDisposable::Dispose()

    IL_0035: endfinally

    } // end handler

    IL_0036: ret

    } // end of method Form1::DisposeTest

    which in human-readable form would be like:

    DataTable myDataTable = new DataTable("Test");



    myDataTable.Columns.Add(new DataColumn("Test", "".GetType()));




    if(myDataTable != null) myDataTable.Dispose();


    What this does is to ensure that complex data types (such as DataTables) are properly "disposed" of even in the event of an exception being thrown.

Page 1 of 1 (12 items)