Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
What's the difference between
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]
Anonymous
March 11, 2004
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? :pAnonymous
March 12, 2004
I think that void is also System.Void, but it is not interchable in C#, isn't it?Anonymous
May 06, 2004
bool System.BooleanAnonymous
July 25, 2004
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?Anonymous
August 28, 2008
PingBack from http://sharpcode.com.br/blogs/rafaelsilva/archive/2008/08/28/afinal-qual-a-diferen-231-a-de-string-e-string.aspxAnonymous
March 06, 2010
Here is a post which explains the difference between a bool and a boolean http://dotnetrobert.com/?q=node/22 Hope you find it useful.Anonymous
February 24, 2011
DateTIme is a Struct!! (value type)... String is a Sealed Class, so you can use as a Object ;)Anonymous
October 05, 2011
what is the differences between a string and a language?Anonymous
October 20, 2011
string is like an alias/shorthand for System.String. Similarly, int is an alias/shosthand for System.Int16. www.jeeshenlee.com/.../difference-between-string-and.htmlAnonymous
March 27, 2012
@williams Alkali: the same difference as the difference between a spoon and a matchbox :PAnonymous
May 17, 2014
There is no such difference between string and String (Syetem.String). The "string" keyword is an alias for System.String in the .NET Framework. net-informations.com/.../stringstring.htmlAnonymous
July 18, 2014
using is a "special" construct to handle automatic disposal of objects that implement the IDisposable interface; e.g. 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 .try { 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 finally { 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"); try { myDataTable.Columns.Add(new DataColumn("Test", "".GetType())); } finally { 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.