4

According to ReferenceSource, the Version class is sealed, ICloneable, IComparable, IComparable<Version>, IEquatable<Version>. It also only stores int values. Is there a particular reason why the .NET programmers chose to make this a class instead of a struct? Why would someone need a null version?

Here's the field declaration block from ReferenceSource:

// AssemblyName depends on the order staying the same
private int _Major;
private int _Minor;
private int _Build = -1;
private int _Revision = -1;

They even make a comment, saying they need to keep the fields aligned. Maybe it's just me, but this is really a struct thing?

Wai Ha Lee
  • 8,598
  • 83
  • 57
  • 92
Philippe Paré
  • 4,279
  • 5
  • 36
  • 56

1 Answers1

5

Why would someone need a null version?

To specify that no version is specified, for instance in AssemblyName as referred to in the comment in your question. An AssemblyName may omit the version when passed to Assembly.Load, for instance, in which case its Version property will be null. Remember that these types were created for .NET 1.0, which didn't have generics, so Nullable<Version> didn't exist yet as an alternative.