Monday, February 1, 2010

Similarities and difference between Class and structure in .NET.

Similarities:
  • Both Class and Structures can have methods, variables and objects.
  • Both can have constructor.
  • Both are user defined types.
Differences:
  • Structure being value type, the variables cannot be assigned to NULL. On the other hand, classes being reference type, a class variable can be assigned to NULL.
  • Structure is allocated on a stack when instantiated, while Class is allocated on a heap.
  • When a method is passed to a class, pass by reference is used. Pass by value is used for struts.
  • A class can have a destructor.

0 Comments: