Thursday, June 11, 2009

Scenarios when you can use struct

Nice article by Chris Eargle on when we should use structs:

He mentions the following criteria for creating struct

1. Does it represent a single value?
2. Will the instance size be under 16 bytes?
3. Should it be immutable (modifications actually make a new copy in memory, forcing you to pass by ref to methods)?
4. Will this rarely need to be boxed (cast to an object)?
5. Will it usually be short-lived?
6. Will it mostly be embedded in other objects?

Click here to read the full article

No comments: