C # types are generally come under two groups.
One is value type.
Another is reference type.
Value type datas are stored in stack memory and reference type datas are stored in heap memory.
Value type variable store the data directly stores the data in memory location .
Reference type values are store in one location and from another location it points to the location of original data. i.e values are stored in one location and its address are stored in another location.
While you copy a value type to another value type variable both act independently because they are treated as entirely different elements.
Example:
Int x,y;
X=10;
Y=x;
Now x and y will both have 10.
X=20;
Now x will contain 20 and y will still hold 10.
Because of they are treated as different variables change in one variable doesn’t affect the content of another variable.
Reference type variables act differently.
When you copy from one variable to another variable of reference type both will point to same location.
Ie both will store the address of same location of data.
So when you alter the original value because of both points to the same location change in one reference type data will also change the data of another variable.
Thank you.
Muthu karthikeyan,Madurai.
91 96293 29142
Tamil nad, india
No comments:
Post a Comment