Part 10: C# Tutorial – Difference between Struct and Classes




We will cover following points in this article

1. Syntax of struct and class
2. Difference between Struct and Classes
3. Understanding difference between Stack & Heap

Syntax
Struct is declared using the struct keyword.
2

Class is declared using the class keyword
3

Struct vs Classes

1. Struct is a value type and inherits from System.Value. Class is a reference type and inherits from System.Object.

2. Struct objects are stored on stack. Class objects are stored on the heap.




3. Struct can’t be base type to classes & to other structure. class can inherit another class and it can be base class to another classes. Both Struct and Class can inherit from an interface.

4. Struct can not have default (parameter less) constructor but it can have parameterized constructors. Class can have default (parameter less) as well as parameterized constructors.

5. Struct can not have destructors. But Class can have destructors.

6. Struct can not initialize its member at the time of declaration. Class can initialize its member at the time of declaration.

7. Struct can be instantiated without using the new keyword. The new keyword should be used to create an object of the class.

8. Struct is by default sealed. It cannot use the abstract, sealed and base keyword. Keywords like abstract, sealed and base can be used in context of classes.


3 thoughts on “Part 10: C# Tutorial – Difference between Struct and Classes

  1. Aubrey Hemming

    Hi There! We are looking for experienced people that are interested in from working their home on a full-time basis. If you want to earn $100 a day, and you don’t mind writing some short opinions up, this is the perfect opportunity for you! Simply check out the link here NOW!

  2. Marilyn Ordaz

    Hi There! We are searching for some people that are interested in from working their home on a part-time basis. If you want to earn $500 a day, and you don’t mind writing some short opinions up, this might be perfect opportunity for you! Simply click the link here NOW!

Leave a Reply

Your email address will not be published. Required fields are marked *