vijay

welcome Netizen

Share Your Knowledge.It is a way to achieve immortality

Saturday, December 1, 2012

Difference between classes and struct(structures) in C#


In c# provides a unique way of packing together different data types called as struct.
Struct is a simple lightweight alternative to class,but struct are basically same as class even though they have some significant difference between struct and class.

Classes
Structs
Classes are declared using Class keyword
Struct are declared using Struct keyword
Its  a refrence type therefore its stored on the heap
It’s a value type and therefore stored on the stack
Support inheritance
Does not support inheritance
Default value of the class type is null
Default value is the value produced by ‘zeroing out’
Permit initialization of instance fields
Do not Permit initialization of instance fields
Permit declaration of parameterless constructors
Do not Permit declaration of parameterless constructors
Destructors is supported
Destructors is not supported
Assignment copies the reference
Assignment copies the vaues


0 comments:

Post a Comment