Here we will try to understand difference between class and structure, as its very important to know the concept.When developer are experienced its important to think that for specific task we should make a class or structure. So here they can know the difference and can go through class or structure as per their need.
Introduction
Here we will know the difference between class and structure, as its very important to know the concept.When developer are experienced its important to think that for specific task we should make a class or structure. So here they can know the difference and can go through class or structure as per their need.
Background
At the time of discussion with senior when they gives task or module to work, its very important to know the difference between class and structure to put the concept and code in a proper way. So here is a small effort to know the concept
Differences are as follows:
1. A struct is a value type i.e it directly contains data. To get the size of a type we can use sizeof control method like sizeof(type). They are stored in stack whereas class is a reference type i.e. they don't contain actual data stored in a variable , they contain a reference to the variable. They are stored in heap.
2. Structure cant have destructor but class can have it.
3. Structure cant inherit from another class whereas a class can inherit. Both structure and classes can inherit from an interface.
4. When you copy a structure into another structure, a new copy of that structure get created and modification on one structure will not affect the values contained by other structure.
5. Explicit parameters constructor are not contained by structures whereas class can contain explicit parameter constructor.
6. Structure do not have destructor whereas class can have it.
Conclusion
Its a small article, but hope it will benefit developers who works in design phase or going to code for specific projects. Thanks enjoy the day with coffee.