C# 为什么.NET';s版本是类而不是结构?

C# 为什么.NET';s版本是类而不是结构?,c#,.net,struct,C#,.net,Struct,根据,版本类是密封的,可克隆的,可兼容的,可兼容的,可兼容的。它还仅存储int值。.NET程序员之所以选择将其作为类而不是结构,有什么特别的原因吗?为什么有人需要null版本 以下是ReferenceSource中的字段声明块: // AssemblyName depends on the order staying the same private int _Major; private int _Minor; private int _Build = -1; private int _Rev

根据,
版本
类是
密封的
可克隆的
可兼容的
可兼容的
可兼容的
。它还仅存储
int
值。.NET程序员之所以选择将其作为类而不是结构,有什么特别的原因吗?为什么有人需要
null
版本

以下是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.0创建的,而.NET 1.0没有泛型,因此
null
作为替代品还不存在。

结构
之间的区别不仅仅是允许
null
值…@WillemVanOnsem OP清楚地知道这一点,因此,问题中提到的所有细节,实际上都是为了使这个类的行为更像一个值。@WillemVanOnsem我知道,但这是我唯一能将它看作类而不是结构的用途…@KonradRudolph,基本上就是这样。我觉得它应该表现得像一个值……相关: