http://www.codeproject.com/Articles/8612/Structs-in-C http://www.csharp-station.com/Tutorial/CSharp/lesson12
Basically use them when you want to have a "complex value type" semantic. An example could be Address. As with all things in our profession it really depends on your context. One example of a key difference: a readonly struct -> all fields is readonly, unlike a readonly object(class) where the instance is readonly but you are free to change individual properties. On Thu, Aug 23, 2012 at 9:23 AM, Arjang Assadi <arjang.ass...@gmail.com>wrote: > Heinrich, > > I still don't understand in plain vanilla business app i.e. GUI ( > WinForm/WPF/Asp.net ) + Domain/BLL + Repository/DLL etc, where would using > structs be beneficial. > Of course a simple example using Classes vs Structs just to compare the > pros and cons would be great but where in business apps that > becomes relevant? > > Regards > > Arjang > > > On 22 August 2012 20:50, Les Hughes <l...@datarev.com.au> wrote: > >> Heinrich Breedt wrote: >> >>> http://msdn.microsoft.com/en-**us/library/ms229017.aspx<http://msdn.microsoft.com/en-us/library/ms229017.aspx> >>> -- >>> Heinrich Breedt >>> >>> “Do not wait to strike till the iron is hot; but make it hot by >>> striking.” - William B. Sprague >>> >> >> That post just touches on the pros/cons of storing data in the heap/stack >> with a brief mention in linking immutable objects. It doesn't mean putting >> things on the stack is automatically a bad idea. In the example I gave in >> my last post, I would be putting 96bytes on instead of 32 for a reference >> type, and it would mean those 96bytes would be duplicated when the function >> returns. >> >> Nothing to really worry about there, whereas if you had a struct with a >> few thousand primitive types/references which is run numerous times, then >> you might want to worry. >> >> The link also says that generally value types are cheaper than reference >> types, and also mentions structs are good for short-lived data. I'd say >> that the example I provided is a good candidate for when to use a struct. >> >> Anyone disagree? >> -- >> Les Hughes >> l...@datarev.com.au >> >> >> > -- Heinrich Breedt “Do not wait to strike till the iron is hot; but make it hot by striking.” - William B. Sprague