jblack1395 (36) [Avatar] Offline
#1
I was looking at the Rect class in chapter 7 and I realized that it would probably make more sense to use a struct for immutable objects rather than a class, esp if the main thing the class does is have getters and a constructor.

Just curious, not necessarily a technical problem but I think it is better coding style to use a struct here, IMO.
jon.skeet (452) [Avatar] Offline
#2
Re: Why not use structs instead of classes in C# code
It could work either way. At 16 bytes it's a reasonably hefty struct, but not unbearably so. It's certainly not cut-and-dried in favour of it being a Rect though: there are plenty of immutable classes which only have a constructor and properties. In particular, look at what the C# 3 compiler generates for anonymous types - they're immutable classes with just constructors and accessors.

Jon