Is it possible to consider a class as an object in C #? After all, does he have methods, properties (public variables)?
2 answers
Class = type, i.e. some "description", metadata. Class is always one. This is a cake recipe if you want.
Object = type instance, i.e. "physical" embodiment of the description. Objects can be many. This is a baked cake recipe. If we talk about the implementation - it is a section of memory containing service data plus the data of the object itself.
In this case, the CLR naturally naturally needs to store information about the type, about what address to call the methods of the type, know which object is of what type, and so on. For this there is a type object (type object) - information stored in the memory about the type that all instances of this type refer to (using the type object pointer in the service data section). Read more about this in Jeffrey Richter’s book "CLR via C #", chapter 4.
However, even despite this, it will be incorrect to call a class an object. You simply do not understand other developers.
- Thanks for the detailed explanation :) - alex-rudenkiy
- @ alex-rudenkiy not for that. Read and reread Richter - be reckoned. - andreycha
- ok, let's read: D - alex-rudenkiy
A class is a class (not an object). An instance of a class (created through the operator new ) is an object.
- 3Perhaps it is better to say “an instance of a class is an object”, and not “an object of a class is an object”, otherwise oil is obtained. - Kromster
- @KromStern, corrected. Although in everyday life the "instance of the class" and the "object class" are equivalent. - Alexis