July 10, 2009

.Net- Difference between Class and Struct.

1- Classes are references type that required to allocate of heap.
1- Struct are values type that do not required to allocate of heap

2- Classes contains a referance of the data.
2- Struct directly contains the original data.

3- Classes can inherit from other classes and interface.
3- Struct can inherit from interface only.

4- Classes are used to store larger data(more data 16 bytes)
4- Struct are used to store less data(16 bytes or less)

5- To instantiate an object of a class, you use the new keyword.
5- You donot require the new keyword to create a instane of a struct.

No comments:

Post a Comment