为什么.NET的版本是一个类而不是结构?

时间:2016-01-09 18:08:30

标签: c# .net struct

根据ReferenceSourceVersion课程为sealedICloneableIComparableIComparable<Version>IEquatable<Version>。它还只存储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;

他们甚至发表评论,称他们需要保持字段一致。也许这只是我,但这真的是一个结构的东西?

1 个答案:

答案 0 :(得分:5)

  

为什么有人需要AssemblyName版本?

指定未指定任何版本,例如在问题评论中引用的AssemblyName中。例如,Assembly.Load传递给Version时可能会省略该版本,在这种情况下,其null属性将为Nullable<Version>。请记住,这些类型是为.NET 1.0创建的,它没有泛型,所以Information:Some files were changed during the build. Additional compilation may be required. Information:09/01/2016, 18:18 - Compilation completed with 10 errors and 0 warnings in 29s 485ms Error:android-apt-compiler: [main] " where item tag is expected /Users/richardcurteis/Desktop/AndroidTraining/Connect3/app/src/main/res/values-v21/styles.xml Error:(1, -1) android-apt-compiler: [main] /Users/richardcurteis/Desktop/AndroidTraining/Connect3/app/src/main/res/values-v21/styles.xml:1: error: Found text "> /Users/richardcurteis/Desktop/AndroidTraining/Connect3/app/src/main/res/values/styles.xml Error:(4, -1) android-apt-compiler: [main] /Users/richardcurteis/Desktop/AndroidTraining/Connect3/app/src/main/res/values/styles.xml:4: error: Error retrieving parent for item: No resource found that matches the given name 'Theme.AppCompat.Light.DarkActionBar'. Error:(8, -1) android-apt-compiler: [main] /Users/richardcurteis/Desktop/AndroidTraining/Connect3/app/src/main/res/values/styles.xml:8: error: Error: No resource found that matches the given name: attr 'colorAccent'. Error:(6, -1) android-apt-compiler: [main] /Users/richardcurteis/Desktop/AndroidTraining/Connect3/app/src/main/res/values/styles.xml:6: error: Error: No resource found that matches the given name: attr 'colorPrimary'. Error:(7, -1) android-apt-compiler: [main] /Users/richardcurteis/Desktop/AndroidTraining/Connect3/app/src/main/res/values/styles.xml:7: error: Error: No resource found that matches the given name: attr 'colorPrimaryDark'. Error:(12, -1) android-apt-compiler: [main] /Users/richardcurteis/Desktop/AndroidTraining/Connect3/app/src/main/res/values/styles.xml:12: error: Error: No resource found that matches the given name: attr 'windowActionBar'. Error:(13, -1) android-apt-compiler: [main] /Users/richardcurteis/Desktop/AndroidTraining/Connect3/app/src/main/res/values/styles.xml:13: error: Error: No resource found that matches the given name: attr 'windowNoTitle'. Error:(16, -1) android-apt-compiler: [main] /Users/richardcurteis/Desktop/AndroidTraining/Connect3/app/src/main/res/values/styles.xml:16: error: Error retrieving parent for item: No resource found that matches the given name 'ThemeOverlay.AppCompat.Dark.ActionBar'. Error:(18, -1) android-apt-compiler: [main] /Users/richardcurteis/Desktop/AndroidTraining/Connect3/app/src/main/res/values/styles.xml:18: error: Error retrieving parent for item: No resource found that matches the given name 'ThemeOverlay.AppCompat.Light'. 还没有作为替代方案存在。