Click here to Skip to main content
15,881,248 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
In the below code:

MIDL
object Wed1 = 8;
object Wed2 = Wed1;
Wed1 = 10;
Console.WriteLine("Wed1 : " +Wed1.ToString());
Console.WriteLine("Wed2 : " +Wed2.ToString());


Output is:

Wed1 : 10
Wed2 : 8

Why isn't it

Wed1 : 10
Wed2 : 10

ie, why isn't it treated like reference type values?
Posted
Updated 16-Jan-11 22:12pm
v2

You are showing the output is as it is and then asking why it isn't exactly as it is.

I think you need to alter the question.

And they are not reference objects because you haven't referenced them, merely outputted to consol.

They are Value Types, not Reference Types.

Reference Types[^]

Value Types[^]

Check them out.
 
Share this answer
 
Comments
[no name] 17-Jan-11 4:12am    
Thank you, that was a typo.
A very good question.

Object is a Alias for a Class Object in .Net Framework.

though Object itself is a class so treated as a ref. type but while assigning any value to Object of class Object, It boxes value inside and after that it's no more a ref. type.

See THIS[^] you will get better idea.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900