Integer Types
sbyte System.SByte
short System.Int16
int System.Int32
long System.Int64
byte System.Byte
ushort System.UInt16
uint System.UInt32
ulong System.UInt64
Floating Point Types
float System.Single
double System.Double
The Decimal Type
decimal System.Decimal
Boolean Type
bool System.Boolean
Character Type
cahr System.Char
Reference Types
object System.Object
string System.String
Note : System.Object is the root type. All other types in the CTS are derived (including value types) from object.
Loading
VulpesPosted Jun 1, 2013, 6:31 AM
A copy of this reference is then assigned to the variable str2 - so at that juncture they both refer to the same string literal.
A reference to where the string literal, "Hello World", is stored in the 'intern pool' is then assigned to the string variable str1, overwriting the existing reference.
This doesn't affect what str2 refers to and so, at that juncture, the variables point to different string literals which is then reflected in what gets printed out.
Although strings, which are the only reference type which supports literals, have some strange properties, the above is in fact normal behavior for references types.
If instead of string, you'd have used a simple custom class, the output would have been similar:
// ...
Output:
mursaleen fayyazPosted Jun 1, 2013, 1:05 AM
string str1 = "Programming World";
string str2 = str1;
str1 = "Hello World";
Console.WriteLine("str1 : " + str1);
Console.WriteLine("str2 : " + str2);
Output:
str1 : Programming World
str2 : Hello World
Guys, Comment on the output and difference from the usual behavior of reference types.
Jignesh TrivediPosted May 31, 2013, 12:16 AM
hi,
Thanks for sharing
also refer below link to understand value type and reference type in depth
http://msdn.microsoft.com/en-us/library/s1ax56ch.aspx
http://msdn.microsoft.com/en-us/library/490f96s2.aspx
hope this will help.
VulpesPosted May 30, 2013, 3:18 PM