Home > DeveloperSection > Blogs > Difference Between Struct and Class in C#

Difference Between Struct and Class in C#


C# C# 
Ratings:
0 Comment(s)
 2021  View(s)
Rate this:

Difference Between Struct and Class in C#


Struct


The struct is value type in C# and it inherits from System.ValueType

The struct value will be stored on the stack memory.

The struct use the array type and its good to use for read only and light weight object.

The struct can't be base type to the classes and also to the other structure.

The struct can only inherit the interfaces

The struct can have only constructor.

The struct can instantiated without using the new keyword.

The struct can't have the default constructor

The struct is by default sealed class hence it will not allow to inherit. It can't use the abstract, sealed, base keyword.

The struct can't use the protected or protected internal modifier.

The struct can't initialize at the time of declaration.

Class 


The class is reference type in C# and it inherits from the System.Object Type

The class object is stored on the heap memory. The object will be under garbage collection and automatically removed when there is no reference to the created objects.

The class uses the collection object type and it can perform all the operations and designed for complex data type storage.

The class can inherit another class, interface and it can be base class to another class.

The class can inherit the interfaces, abstract classes.

The class can have the constructor and destructor.

The new keyword should be used to create the object for the class

The class will have the default constructor

The class can be declared as abstract, sealed class

The class can use all the access modifiers.

The class can have the initializes fields.


Don't want to miss updates? Please click the below button!

Follow MindStick