WHAT IS THE DIFFERENCE BETWEEN A CLASS AND A STRUCTURE?

Sumit Kesarwani

Total Post:782

Points:3910
Posted by  Sumit Kesarwani
C# 
C#
 939  View(s)
Ratings:
Rate this:
  1. Sumit Kesarwani

    Post:782

    Points:3910
    What is the difference between a class and a structure?

    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.

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!