Difference between classes and structures?

 Posted by Majith on 9/6/2008 | Category: C# Interview questions | Views: 22915

A struct is a value type and a class is a reference type.

When we instantiate a class, memory will be allocated on the heap and when struct gets initiated it gets memory on the stack.

Classes can have explicit parameter less constructors. But structs dosn't have this.

Classes support inheritance. No inheritance for structs.

A struct cannot inherit from another struct or class, and it cannot be the base of a class. Like classes, structures can implement interfaces.

Asked In: Many Interviews | Alert Moderator 

Comments or Responses

Posted by: Webmaster on: 1/3/2011 | Points: 10
A good article on difference between Class and Struct is written at http://www.jaggersoft.com/pubs/StructsVsClasses.htm. A must read article to know about Class and Struct.


Login to post response