What is the Difference among CLASS , OBJECTS and REFERENCE ?
In teams of LOGIC so i can understand
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
VulpesPosted Aug 14, 2012, 11:36 AM
Here, MyClass is a blueprint for creating objects which have a single property of type int.
MyClass has a constructor which initializes the MyInt property.
The following expression creates a new instance (i.e. an object) of type MyClass whose property is equal to 3:
new MyClass(3);
This object is stored in an area of memory known as the heap. The above expression also returns a pointer to where this object is stored.
However, this isn't an ordinary pointer which never changes because the operation of the garbage collector (which cleans up objects which are no longer used) may cause the object to be relocated elsewhere in memory. It is instead called 'a reference' and, if the object is relocated, references are automatically updated to point to the same object as before.
Finally, this line causes the reference to be stored in the variable mc:
MyClass mc = new MyClass(3);
We can now use this variable to access the object's property and write it to the console using this line:
Console.WriteLine(mc.MyInt);
Abhishek Kumar RaviPosted Aug 14, 2012, 9:25 AM
VulpesPosted Aug 14, 2012, 6:18 AM