Q:

C# struct and class variable value

i know that struct is of value type and class is reference type but when i execute the following code why im getting the two different answer 
can any one explain a bit 
[struct|class] values {
    public int x, y;

    public values (int x, int y) {
        this.x = x;
        this.y = y;
    }
}

values v = new values(12, 13);
object o = v;
v.x = 2;
Console.WriteLine(((values)o).x);

Outputs 
when 

it is class : output is   2
it is struct :output is   12

Can any one explain me?
Thanks 

A:

The one line that behaves very differently for struct or class is 
  object o = v;

When Values is a reference type, o becomes a copy of the reference v. There still is only 1 instance of Values. 
When Values is a value type, o becomes a reference to the boxed copy of the instance itself. In this case the assignment creates a 2nd instance and you execute v.x = 2 on the original. The copy is not affected.

Your example includes boxing and that is an unnecessary complication, when you use values o = v; you will get the same output. The line then creates a normal copy (2nd instance) without boxing. 
To sum it up: the main difference between value and reference type is in copy semantics. You will notice different behaviour in simple assignments (x = y) and in parameter passing (foo(x)).  
You can expect gotchas with mutable value types. As an exercise, see what f.Myvalue.x = 2; does with Values as class or struct with  
 class Foo { public Values MyValue  { get; set; } }

