Version 类

定义

表示程序集、操作系统或公共语言运行时的版本号。 此类不能被继承。

public ref class Version sealed : IComparable, IComparable<Version ^>, IEquatable<Version ^>
public ref class Version sealed : ICloneable, IComparable, IComparable<Version ^>, IEquatable<Version ^>, ISpanFormattable, IUtf8SpanFormattable, IUtf8SpanParsable<Version ^>
public ref class Version sealed : ICloneable, IComparable, IComparable<Version ^>, IEquatable<Version ^>
public ref class Version sealed : ICloneable, IComparable, IComparable<Version ^>, IEquatable<Version ^>, ISpanFormattable
public ref class Version sealed : ICloneable, IComparable, IComparable<Version ^>, IEquatable<Version ^>, ISpanFormattable, IUtf8SpanFormattable
public ref class Version sealed : ICloneable, IComparable
public sealed class Version : IComparable, IComparable<Version>, IEquatable<Version>
public sealed class Version : ICloneable, IComparable, IComparable<Version>, IEquatable<Version>, ISpanFormattable, IUtf8SpanFormattable, IUtf8SpanParsable<Version>
public sealed class Version : ICloneable, IComparable, IComparable<Version>, IEquatable<Version>
public sealed class Version : ICloneable, IComparable, IComparable<Version>, IEquatable<Version>, ISpanFormattable
public sealed class Version : ICloneable, IComparable, IComparable<Version>, IEquatable<Version>, ISpanFormattable, IUtf8SpanFormattable
[System.Serializable]
public sealed class Version : ICloneable, IComparable
[System.Serializable]
[System.Runtime.InteropServices.ComVisible(true)]
public sealed class Version : ICloneable, IComparable, IComparable<Version>, IEquatable<Version>
type Version = class
    interface IComparable
    interface IComparable<Version>
    interface IEquatable<Version>
type Version = class
    interface ICloneable
    interface IComparable
    interface IComparable<Version>
    interface IEquatable<Version>
    interface IFormattable
    interface ISpanFormattable
    interface IUtf8SpanFormattable
    interface IUtf8SpanParsable<Version>
type Version = class
    interface ICloneable
    interface IComparable
    interface IComparable<Version>
    interface IEquatable<Version>
type Version = class
    interface ICloneable
    interface IComparable
    interface IComparable<Version>
    interface IEquatable<Version>
    interface ISpanFormattable
    interface IFormattable
type Version = class
    interface ICloneable
    interface IComparable
    interface IComparable<Version>
    interface IEquatable<Version>
    interface IFormattable
    interface ISpanFormattable
type Version = class
    interface ICloneable
    interface IComparable
    interface IComparable<Version>
    interface IEquatable<Version>
    interface IFormattable
    interface ISpanFormattable
    interface IUtf8SpanFormattable
type Version = class
    interface IComparable
    interface IComparable<Version>
    interface IEquatable<Version>
    interface ICloneable
[<System.Serializable>]
type Version = class
    interface ICloneable
    interface IComparable
[<System.Serializable>]
[<System.Runtime.InteropServices.ComVisible(true)>]
type Version = class
    interface ICloneable
    interface IComparable
    interface IComparable<Version>
    interface IEquatable<Version>
Public NotInheritable Class Version
Implements IComparable, IComparable(Of Version), IEquatable(Of Version)
Public NotInheritable Class Version
Implements ICloneable, IComparable, IComparable(Of Version), IEquatable(Of Version), ISpanFormattable, IUtf8SpanFormattable, IUtf8SpanParsable(Of Version)
Public NotInheritable Class Version
Implements ICloneable, IComparable, IComparable(Of Version), IEquatable(Of Version)
Public NotInheritable Class Version
Implements ICloneable, IComparable, IComparable(Of Version), IEquatable(Of Version), ISpanFormattable
Public NotInheritable Class Version
Implements ICloneable, IComparable, IComparable(Of Version), IEquatable(Of Version), ISpanFormattable, IUtf8SpanFormattable
Public NotInheritable Class Version
Implements ICloneable, IComparable
继承
Version
属性
实现

示例

以下示例使用 AssemblyVersionAttribute 特性将版本号分配给程序集。 在编译时,此版本信息随程序集的元数据一起存储。 在运行时,该示例检索程序集中找到的类型上的属性的值Type.Assembly以获取对执行程序集的引用,并从方法返回Version的对象的属性AssemblyName检索程序集的版本信息Assembly.GetName

using System;
using System.Reflection;

[assembly:AssemblyVersionAttribute("2.0.1")]

public class Example1
{
   public static void Main()
   {
      Assembly thisAssem = typeof(Example1).Assembly;
      AssemblyName thisAssemName = thisAssem.GetName();
       
      Version ver = thisAssemName.Version;
       
      Console.WriteLine("This is version {0} of {1}.", ver, thisAssemName.Name);    
   }
}
// The example displays the following output:
//        This is version 2.0.1.0 of Example1.
open System.Reflection

[<assembly: AssemblyVersionAttribute "2.0.1">]
do ()

type Example1 = class end

let thisAssem = typeof<Example1>.Assembly
let thisAssemName = thisAssem.GetName()
   
let ver = thisAssemName.Version
   
printfn $"This is version {ver} of {thisAssemName.Name}."
// The example displays the following output:
//        This is version 2.0.1.0 of Example1.
Imports System.Reflection

<Assembly:AssemblyVersionAttribute("2.0.1")>
Module Example1
   Public Sub Main()
       Dim thisAssem As Assembly = GetType(Example1).Assembly
       Dim thisAssemName As AssemblyName = thisAssem.GetName()
       
       Dim ver As Version = thisAssemName.Version
       
       Console.WriteLine("This is version {0} of {1}.", ver, thisAssemName.Name)    
   End Sub
End Module
' The example displays the following output:
'      This is version 2.0.1.0 of Example1.

注解

有关此 API 的详细信息,请参阅 版本补充 API 备注

构造函数

名称 说明
Version()

初始化 Version 类的新实例。

Version(Int32, Int32, Int32, Int32)

使用指定的主要、次要、生成和修订号初始化类的新实例 Version

Version(Int32, Int32, Int32)

使用指定的主要、次要值和生成值初始化类的新实例 Version

Version(Int32, Int32)

使用指定的主值和次要值初始化类的新实例 Version

Version(String)

使用指定的字符串初始化类的新实例 Version

属性

名称 说明
Build

获取当前 Version 对象的版本号的生成组件的值。

Major

获取当前 Version 对象的版本号的主要组件的值。

MajorRevision

获取修订号的高 16 位。

Minor

获取当前 Version 对象的版本号的次要组件的值。

MinorRevision

获取修订号的低 16 位。

Revision

获取当前 Version 对象的版本号的修订组件的值。

方法

名称 说明
Clone()

返回一个新 Version 对象,其值与当前 Version 对象相同。

CompareTo(Object)

将当前 Version 对象与指定对象进行比较,并返回其相对值的指示。

CompareTo(Version)

将当前 Version 对象与指定 Version 对象进行比较,并返回其相对值的指示。

Equals(Object)

返回一个值,该值指示当前 Version 对象是否等于指定的对象。

Equals(Version)

返回一个值,该值指示当前 Version 对象和指定的 Version 对象是否表示相同的值。

GetHashCode()

返回当前 Version 对象的哈希代码。

GetType()

获取当前实例的 Type

(继承自 Object)
MemberwiseClone()

创建当前 Object的浅表副本。

(继承自 Object)
Parse(ReadOnlySpan<Byte>)

将表示版本号的 UTF-8 字符的指定只读范围转换为等效的 Version 对象。

Parse(ReadOnlySpan<Char>)

将表示版本号的指定只读字符范围转换为等效 Version 对象。

Parse(String)

将版本号的字符串表示形式转换为等效 Version 对象。

ToString()

将当前 Version 对象的值转换为其等效 String 表示形式。

ToString(Int32)

将当前 Version 对象的值转换为其等效 String 表示形式。 指定的计数指示要返回的组件数。

TryFormat(Span<Byte>, Int32, Int32)

尝试将此版本实例格式化为字节范围。

TryFormat(Span<Byte>, Int32)

尝试将此版本实例格式化为字节范围。

TryFormat(Span<Char>, Int32, Int32)

尝试将此版本实例格式化为字符范围。

TryFormat(Span<Char>, Int32)

尝试将此版本实例格式化为字符范围。

TryParse(ReadOnlySpan<Byte>, Version)

尝试将版本号的 UTF-8 表示形式转换为等效的 Version 对象,并返回一个值,该值指示转换是否成功。

TryParse(ReadOnlySpan<Char>, Version)

尝试将表示版本号的指定只读字符范围转换为等效 Version 对象,并返回一个值,该值指示转换是否成功。

TryParse(String, Version)

尝试将版本号的字符串表示形式转换为等效 Version 对象,并返回一个值,该值指示转换是否成功。

运营商

名称 说明
Equality(Version, Version)

确定两个指定的 Version 对象是否相等。

GreaterThan(Version, Version)

确定第一个指定 Version 对象是否大于第二个指定 Version 对象。

GreaterThanOrEqual(Version, Version)

确定第一个指定 Version 对象是否大于或等于第二个指定 Version 对象。

Inequality(Version, Version)

确定两个指定的 Version 对象是否不相等。

LessThan(Version, Version)

确定第一个指定 Version 对象是否小于第二个指定 Version 对象。

LessThanOrEqual(Version, Version)

确定第一个指定的 Version 对象是否小于或等于第二个 Version 对象。

显式接口实现

名称 说明
IComparable.CompareTo(Object)

将当前 Version 对象与指定对象进行比较,并返回其相对值的指示。

IFormattable.ToString(String, IFormatProvider)

使用指定格式设置当前实例的值的格式。

ISpanFormattable.TryFormat(Span<Char>, Int32, ReadOnlySpan<Char>, IFormatProvider)

尝试将当前实例的值格式化为提供的字符范围。

IUtf8SpanFormattable.TryFormat(Span<Byte>, Int32, ReadOnlySpan<Char>, IFormatProvider)

尝试将当前实例的值格式化为 UTF-8,并将其设置为提供的字节范围。

IUtf8SpanParsable<Version>.Parse(ReadOnlySpan<Byte>, IFormatProvider)

表示程序集、操作系统或公共语言运行时的版本号。 此类不能被继承。

IUtf8SpanParsable<Version>.TryParse(ReadOnlySpan<Byte>, IFormatProvider, Version)

表示程序集、操作系统或公共语言运行时的版本号。 此类不能被继承。

适用于