I personally find a lot of value in value types (excuse the pun)
Imagine if there where no value types and you did some control manipulation
like this
textbox1.Size = textbox2.Size;
then later on did
textbox1.Size.Height *= 2;
This would double the height of textbox1 and (probably unintentially)double
the height of textbox2. The handy thing about Value types is that every
reference is to a different copy so assigning one from the other copies it.
This is handy when you want this and is also more performant when passing
them as parameters to functions as long as they are lightweight as
recommended. They should represent a complete piece of information in the
same way as the Size, Point, Rectangle structures do.
Structures all help with encapsulation as with the textbox example above,
giving out a reference to a Size class would enable some body to change the
height of the textbox without using the height property. With structs, this
isnt possible as when you get the return value from the Size property, it is
a copy of the textboxes internal data, not a direct reference to it.
I'm not a great technical authore but here is a link to a good document on
the diferences in practice:
http://www.awprofessional.com/content/images/0321245660/items/wagner_item6.pdf HTH
--
Ciaran O''Donnell
http://wannabedeveloper.spaces.live.com [quoted text, click to view] "Tim" wrote:
> Hi Gurus,
> I am newbie and little confused with Classes(Ref type) and Structures(Value
> type).
> I know how to use both classes and Structures and also know the difference
> between value type and ref type, but I don't see much use of structures.
> Please help me by answering the question below.
>
> 1. Is there anything a Structure can do and Class cannot.
> 2. What is the advantage of Structure over Classes
> 3. When should we use Structure.
>
> Please clear my doubt. I'll appreciate any help you can provide
> Thanks, Tim.
>
>