Version.ToString 方法

定義

將目前 Version 物件的值轉換為它的對等 String 表示。Converts the value of the current Version object to its equivalent String representation.

多載

ToString()

將目前 Version 物件的值轉換為它的對等 String 表示。Converts the value of the current Version object to its equivalent String representation.

ToString(Int32)

將目前 Version 物件的值轉換為它的對等 String 表示。Converts the value of the current Version object to its equivalent String representation. 指定的計數指示要傳回的元件數目。A specified count indicates the number of components to return.

ToString()

將目前 Version 物件的值轉換為它的對等 String 表示。Converts the value of the current Version object to its equivalent String representation.

public:
 override System::String ^ ToString();
public override string ToString ();
override this.ToString : unit -> string
Public Overrides Function ToString () As String

傳回

目前 String 物件的主要、次要、組建和修訂元件值的 Version 表示,如下列格式所述。The String representation of the values of the major, minor, build, and revision components of the current Version object, as depicted in the following format. 每個元件是以句號字元 ('.') 隔開。Each component is separated by a period character ('.'). 方括弧 ('[' 和 ']') 指示如果未定義則不會在傳回值中出現的元件:Square brackets ('[' and ']') indicate a component that will not appear in the return value if the component is not defined: major.minor[.build[.revision]]major.minor[.build[.revision]] 例如,如果您使用建構函式 Version(1,1) 建立 Version 物件,則傳回字串是 "1.1"。For example, if you create a Version object using the constructor Version(1,1), the returned string is "1.1". 如果您使用建構函式 Version(1,3,4,2) 建立 Version 物件,則傳回字串是 "1.3.4.2"。If you create a Version object using the constructor Version(1,3,4,2), the returned string is "1.3.4.2".

ToString(Int32)

將目前 Version 物件的值轉換為它的對等 String 表示。Converts the value of the current Version object to its equivalent String representation. 指定的計數指示要傳回的元件數目。A specified count indicates the number of components to return.

public:
 System::String ^ ToString(int fieldCount);
public string ToString (int fieldCount);
override this.ToString : int -> string
Public Function ToString (fieldCount As Integer) As String

參數

fieldCount
Int32

要傳回的元件數目。The number of components to return. fieldCount 的範圍從 0 到 4。The fieldCount ranges from 0 to 4.

傳回

目前 String 物件的主要、次要、組建和修訂元件值的 Version 表示,每個元件都以句號字元 ('.') 隔開。The String representation of the values of the major, minor, build, and revision components of the current Version object, each separated by a period character ('.'). fieldCount 參數會判斷有多少元件傳回。The fieldCount parameter determines how many components are returned.

fieldCountfieldCount 傳回值Return Value
00 空字串 ("")。An empty string ("").
11 majormajor
22 major.minormajor.minor
33 major.minor.buildmajor.minor.build
44 major.minor.build.revisionmajor.minor.build.revision

例如,如果您使用建構函式 Version(1,3,5) 建立 Version 物件,則 ToString(2) 會傳回 "1.3",ToString(4) 則會擲回例外狀況。For example, if you create Version object using the constructor Version(1,3,5), ToString(2) returns "1.3" and ToString(4) throws an exception.

例外狀況

fieldCount 小於 0 或大於 4。fieldCount is less than 0, or more than 4.

-或--or- fieldCount 大於在目前 Version 物件中定義的元件數目。fieldCount is more than the number of components defined in the current Version object.

適用於