Structure Vs Class  
Author Message
ALiry





PostPosted: Visual Basic Express Edition, Structure Vs Class Top

Can anyone describe the exact defrence between Class and Structure
We can use bouth many times.
When should we use a Class and when a Structure



Visual Studio Express Editions2  
 
 
DotNetFun





PostPosted: Visual Basic Express Edition, Structure Vs Class Top

Classes are stored in memory via a heap whereas structs are stored in memory via a stack. Stacks are faster and more efficient and there's no need for the CLR garbage collector ro reclaim memory for structs (which takes time and resources). Structs are value types and all value types are stored on the stack.

Basically, classes are reference types and structs are value types. Reference types get stored differently than value types. Value types are stored more efficiently but only when they contain little data.



 
 
jvanderbeek





PostPosted: Visual Basic Express Edition, Structure Vs Class Top

This video from Microsoft entitled 'The Rich type system' discusses this in detail, on when to use class or struct in detail.

http://msdn.microsoft.com/netframework/programming/classlibraries/richtypesystem/



 
 
M.S.P.Saami





PostPosted: Visual Basic Express Edition, Structure Vs Class Top

Hai,

Wat DotNetFun said was true. And here is other things that depicts the differences.

Class can extend another class, can be extended to other class.

Structures cannot extend anything or extended to other thing.

But both can implements Interfaces.

right...



 
 
SJWhiteley





PostPosted: Visual Basic Express Edition, Structure Vs Class Top

Pay attention to the video that Jelle van der Beek linked to: even though it drags on a little, it's quite good and mentions a big drawback of structures. Indeed, I've found the class capability of the framework extremely versatile.