0 votes
in C Sharp by

What is the difference between a struct and a class in C#?

1 Answer

0 votes
by

Class and struct both are the user defined data type but have some major difference:

** Struct**

The struct is value type in C-Sharp and it inherits from System.Value Type.

Struct is usually used for smaller amounts of data.

Struct can't be inherited to other type.

A structure can't be abstract.

No need to create object by new keyword.

Do not have permission to create any default constructor.

Class

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

Classes are usually used for large amounts of data.

Classes can be inherited to other class.

A class can be abstract type.

We can't use an object of a class with using new keyword.

We can create a default constructor.

Related questions

0 votes
asked May 6, 2020 in C Sharp by SakshiSharma
0 votes
asked Oct 18, 2019 in C Sharp by Robin
...