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.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
VulpesRank #55 · 29.2K reputationPosted Aug 14, 2012, 2:18 AM EDT
Abhishek Kumar RaviRank #251 · 10K reputationPosted Aug 14, 2012, 5:25 AM EDT
VulpesRank #55 · 29.2K reputationPosted Aug 14, 2012, 7:36 AM EDT
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);