Know the answer? Post it. Somebody with the same question will find it here.
Afzaal Ahmad ZeeshanRank #60 · 27.6K reputationPosted Mar 23, 2016, 12:38 PM EDT
+1
There are many differences between classes and structs. In C#, classes are the core feature for object-oriented programming, whereas structures are based on the native C++ style structures; with a type of pass by value.
Other than that, you can inherit classes, and classes can again inherit classes. Structs don't support object-oriented programming.
Classes are reference type objects, whereas structs are value type objects. That is why, only classes can be null and structures have to support a default value.
For more on that, please read the following MSDN links:
Class is a reference type and its object is created on the heap memory.
Class can inherit the another class.
Class can have the all types of constructor and destructor.
The member variable of class can be initialized directly.
Struct :
Structure is a value type that is why its object is created on the stack memory.
Structure does not support the inheritance.
Structure can only have the parametrized constructor. it means a structure can not have the non-parametrized constructor,default constructor and destructor also.
Afzaal Ahmad ZeeshanRank #60 · 27.6K reputationPosted Mar 23, 2016, 12:38 PM EDT
Ravi PatelRank #439 · 5.7K reputationPosted Mar 23, 2016, 5:30 PM EDT
Rajeesh MenothRank #118 · 18.4K reputationPosted Mar 23, 2016, 8:30 PM EDT
Abhay ShankerRank #375 · 6.7K reputationPosted Mar 23, 2016, 11:42 PM EDT
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questionsTop experts