The assignment of a value type instance.

Tripati_tutu
Posted by Tripati_tutu under C# category on | Points: 40 | Views : 1661
    int a;
static void Main(string[] args)
{
Value v1 = new Value();
v1.a = 10;

Value v2 = v1; // this statement copies value from v1 to v2.

Console.WriteLine(v1.a); // here the value is 10
Console.WriteLine(v2.a); // here the value is 10

v1.a = 20; // here the v1.a value is changed.

Console.WriteLine(v1.a); // here the value is 20
Console.WriteLine(v2.a); // here the value is 10
}

Comments or Responses

Posted by: T.saravanan on: 2/20/2011 Level:Silver | Status: [Member] [MVP] | Points: 10
Hi,

doubts in your code...
1.Are you using 4.0 framework because i will try this code in 3.5 framework i am not get Value (Value v1 = new Value();) object in this framework.
2.In v1.a... what is 'a'

Kindly clarify those doubts to me...
Posted by: Tripati_tutu on: 2/21/2011 Level:Bronze | Status: [Member] | Points: 10
This is in .NET 4.0
Here 'a' is a variable and I am assigning the value to that variable with the help of Value object.
Posted by: T.saravanan on: 2/21/2011 Level:Silver | Status: [Member] [MVP] | Points: 10
Ok.Thanks,
But you did not assign the Variable 'a' .
Kindly checked it out and change it.
Posted by: Tripati_tutu on: 2/21/2011 Level:Bronze | Status: [Member] | Points: 10
Now I have changed.
Please check it out.

Thanks T.saravanan.

Regards,
Tripati
Posted by: Tripati.patro on: 2/21/2011 Level:Starter | Status: [Member] | Points: 10
Good Example.

Login to post response