-----------------------------------------------------------
New Message on BDOTNET
-----------------------------------------------------------
From: Sijin
Message 3 in Discussion
Hi, int i=123; //i is value type object o=i; //o is reference type, so when you
assign a value type to a reference type the frameowrk creates a boxed object on the
heap with the same value, at this point there is the value i on stack and the
reference type object o on the heap i=456; // you are manipulating the value on the
stack the object o on the heap does not get affected.
Console.WriteLine(o.ToString()); // Since o still has the value 123 that is what gets
printed. When the above code is executed it is printing as 123, When i change
into like below object i=new string(new char[]{'1'}); //i is reference type,
i------->['1'] object o=i; //o is reference type, so basically a pointer to the
actual object on the heap gets assigned to o. Now o and i refer to the same object. o
------->['1']<-------- i i="456"; //Now you are assigning a new object to the
reference i i -------->['456] o--------->['1'] Console.WriteLine(o.ToString());
//Since o still points to the old object it will print 1 Then also it is printing 1.
When I assign a ref type it is going to assign the reference only. Then how this is
showing the value as 1 it has to show as 456 only right. One more question all
objects are derived from System.object class so that all objects will have the
ToString() method. When declare a interger variable as int i=1234; Then When I write
i.ToString(); Its converting into string >From where this ToString() method came from
coz i is a value type. System.Object is the base class of System.ValueType Hope
that clears it up. Sijin Joseph http://www.indiangeek.net
http://weblogs.asp.net/sjoseph
-----------------------------------------------------------
To stop getting this e-mail, or change how often it arrives, go to your E-mail
Settings.
http://groups.msn.com/BDOTNET/_emailsettings.msnw
Need help? If you've forgotten your password, please go to Passport Member Services.
http://groups.msn.com/_passportredir.msnw?ppmprop=help
For other questions or feedback, go to our Contact Us page.
http://groups.msn.com/contact
If you do not want to receive future e-mail from this MSN group, or if you received
this message by mistake, please click the "Remove" link below. On the pre-addressed
e-mail message that opens, simply click "Send". Your e-mail address will be deleted
from this group's mailing list.
mailto:[EMAIL PROTECTED]