Wednesday, August 12, 2020

What is the difference between struct and class in c#

 Difference between Structs and Classes 

Structs are value type whereas Classes are reference type. 

Structs are stored on the stack whereas Classes are stored on the heap. 

When you copy struct into another struct, a new copy of that struct gets created modified of one struct won't affect the value of the other struct.

Class can create a subclass that will inherit parent's properties and methods, whereas Structure does not support the inheritance. 

A class has all members private by default. 

A struct is a class where members are public by default. 

 Boxing and unboxing operations are used to convert between a struct type and object.