Home > DeveloperSection > Interviews > What is the difference between a class and a structure?

Posted on    September-04-2014 11:30 PM

 C# C# 
Ratings:
 1 Answer(s)
  757  View(s)
Rate this:

Sumit Kesarwani

Total Post:782

Points:3910
Posted on    September-04-2014 12:00 AM

Class:

A class is a reference type.

While instantiating a class, CLR allocates memory for its instance in heap.

Classes support inheritance.

Variables of a class can be assigned as null.

Class can contain constructor/destructor.

Structure:

A structure is a value type.

In structure, memory is allocated on stack.

Structures do not support inheritance.

Structure members cannot have null values.

Structure does not require constructor/destructor and members can be initialiazed automatically.


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

Follow MindStick