Why is the 'System.Version' a reference type (class) and not a value type (struct)?

According to Microsoft's own guidelines you should prefer a class to a structure when the instance is at least 16 bytes. Since System. Version stores four Int32, each consisting of four bytes for a total of 16 bytes, they followed their own advice and made it a class.

According to Microsoft's own guidelines, you should prefer a class to a structure when the instance is at least 16 bytes. Since System. Version stores four Int32, each consisting of four bytes for a total of 16 bytes, they followed their own advice and made it a class.

And what is with System. DateTime? There are more than 4 properties that are System.

Int32 values. – Marcel J. Kloubert Oct 12 at 20:58 1 @Marcel DateTime has a single 64 bit integer field.So it's just 8 bytes total.

The number of properties is irrelevant. – CodeInChaos Oct 12 at 21:00 1 @MarcelJ. Kloubert: DateTime is an 8-byte struct.

Way below the 16 byte cutoff. – Allon Guralnek Oct 12 at 21:01 ah, ok.It calculates other properties, like Minutes or Seconds, from the inner ticks value... – Marcel J. Kloubert Oct 12 at 21:05.

I can't say for sure, but one reason might be immutability. The properties in the Version class are all read-only. Whereas it's possible to declare readonly fields in a struct, Eric Lippert points that readonly on a struct field is a lie.

Making it a class ensures immutability.

According to Microsoft's guidlines, you should only define a struct if it is immutable. So it seems odd that Microsoft would follow an opposite logic, where structs should be used for mutable types, just because immutability cannot be guaranteed by the compiler. – Allon Guralnek Oct 12 at 20:56.

Another point that may have been relevant in the design process is that Version is ComVisible. As such, it makes more sense to expose it to COM as a coclass (behavior, without guarantees about internal layout) rather than as a COM struct (which specifies an in-memory layout like a C struct).

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions