In C# language, a class is defined by using the | In C# language, a structure is defined by using the |
A class is a reference type and its object is created on the heap. | A structure is a value type and its object is created on the stack. |
A class can be inherited from a class or struct. | A structure does not support inheritance and cannot be inherited from any class or struct. |
A class is more efficient when used in collections. | A structure is more efficient when used in arrays. |
A class can have a default constructor without any parameter, which is provided by the common language runtime (or CLR). It also supports destructors. | A structure cannot have any parameterless constructor or the default constructor that is provided by the CLR. It also cannot have destructors. |
An instance field or a member variable can be initialized in a class. | An instance field or a member variable cannot be initialized in a struct. |
A class cannot be created without using the | A struct can be created without using the |
The following are the differences between a class and a structure in C# language:
Posted by
Manoj
Wednesday, January 20, 2010
at
5:29 PM
Subscribe to:
Posts (Atom)