Thursday, May 14, 2009

Difference between struct and Class

Difference between struct and Class
1. Struct are value type and stored on stack while class are reference type and store on heap.
2. Struct do not support inheritance while class supports inheritance, However struct can implements interface.
3. Struct should be used when you want to use a small data structure while class is better choice for complex data structure.
4. The fourth significant difference between class objects and struct objects refers to constructors. Constructors are supported by structs in the C# language, and you can define constructors for structs in exactly the same manner as you would for classes. If you are not familiar with constructors, they are methods with the same name as the struct or class. However, the only exception with struct constructors is that you are not permitted to define a constructor that takes no arguments.
5. By default, Structure data members are public but class data members are private.
6. In Structure we can’t declare any default constructor explicitly because it provides by .net framework. But in class we can declare default constructor explicitly.

No comments:

Post a Comment

Locations of visitors to this page