Thursday, 7 April 2016

What is the difference between a class and a structure?

Class:
  1. A class is a reference type.
  2. While instantiating a class, CLR allocates memory for its instance in heap.
  3. Classes support inheritance.
  4. Variables of a class can be assigned as null.
  5. Class can contain constructor/destructor.

Structure:
  1. A structure is a value type.
  2. In structure, memory is allocated on stack.
  3. Structures do not support inheritance.
  4. Structure members cannot have null values.
  5. Structure does not require constructor/destructor and members can be initialiazed automatically.

No comments:

Post a Comment

Featured post

What is SharePoint?

Microsoft SharePoint is an extensible platform that provides a range of products that can help organizations with solution for a variety...