Wednesday, August 10, 2011

Are Structs really lightweight classes?

We usually have very common myth about "Struts" that they are simple and should be used as data transfer types and they are lighter in terms of performance as they do not require garbage collection.

But that is not fact in all cases.

We should be careful while choosing between struct or reference type.

It could more better to pass few bytes of data as reference rather than copying all the data, example passing Hashtable instance. Just imagine if Hashtable is values type, passing whole hashtable instead of the reference. 

No comments: