根据ReferenceSource,Version
类是sealed
,ICloneable
,IComparable
,IComparable<Version>
,IEquatable<Version>
,int
。它也只存储null
值。为什么.NET程序员选择将它作为一个类而不是一个结构,这有什么特别的原因吗?为什么有人需要版本?
这是来自referencesource的字段声明块:
// AssemblyName depends on the order staying the same
private int _Major;
private int _Minor;
private int _Build = -1;
private int _Revision = -1;
他们甚至发表评论,说他们需要保持字段对齐。也许只有我一个人,但这真的是一个结构化的东西?
最佳答案
为什么有人需要null
版本?
指定不指定版本,例如在AssemblyName
中,如问题中的注释中所述。例如,AssemblyName
可以在传递给Assembly.Load
时省略版本,在这种情况下,它的Version
属性将是null
。请记住,这些类型是为.NET 1创建的,它们没有泛型,所以Nullable<Version>
还不存在。