Version.Parse 메서드
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
오버로드
| Name | Description |
|---|---|
| Parse(ReadOnlySpan<Byte>) |
버전 번호를 나타내는 UTF-8 문자의 지정된 읽기 전용 범위를 해당하는 Version 개체로 변환합니다. |
| Parse(ReadOnlySpan<Char>) |
버전 번호를 나타내는 지정된 읽기 전용 문자 범위를 해당하는 Version 개체로 변환합니다. |
| Parse(String) |
버전 번호의 문자열 표현을 해당하는 Version 개체로 변환합니다. |
Parse(ReadOnlySpan<Byte>)
- Source:
- Version.cs
- Source:
- Version.cs
버전 번호를 나타내는 UTF-8 문자의 지정된 읽기 전용 범위를 해당하는 Version 개체로 변환합니다.
public:
static Version ^ Parse(ReadOnlySpan<System::Byte> utf8Text);
public static Version Parse(ReadOnlySpan<byte> utf8Text);
static member Parse : ReadOnlySpan<byte> -> Version
Public Shared Function Parse (utf8Text As ReadOnlySpan(Of Byte)) As Version
매개 변수
- utf8Text
- ReadOnlySpan<Byte>
변환할 버전 번호를 포함하는 UTF-8 문자의 읽기 전용 범위입니다.
반품
매개 변수에 지정된 utf8Text 버전 번호와 동일한 개체입니다.
예외
utf8Text 에는 2개 또는 4개 이상의 버전 구성 요소가 있습니다.
하나 이상의 구성 요소가 utf8Text 0보다 작습니다.
하나 이상의 구성 요소가 utf8Text 정수가 아닙니다.
하나 utf8Text 이상의 구성 요소가 .보다 MaxValue큰 숫자를 나타냅니다.
적용 대상
Parse(ReadOnlySpan<Char>)
- Source:
- Version.cs
- Source:
- Version.cs
- Source:
- Version.cs
- Source:
- Version.cs
- Source:
- Version.cs
버전 번호를 나타내는 지정된 읽기 전용 문자 범위를 해당하는 Version 개체로 변환합니다.
public:
static Version ^ Parse(ReadOnlySpan<char> input);
public static Version Parse(ReadOnlySpan<char> input);
static member Parse : ReadOnlySpan<char> -> Version
Public Shared Function Parse (input As ReadOnlySpan(Of Char)) As Version
매개 변수
- input
- ReadOnlySpan<Char>
변환할 버전 번호를 포함하는 읽기 전용 문자 범위입니다.
반품
매개 변수에 지정된 input 버전 번호와 동일한 개체입니다.
예외
input 에는 2개 또는 4개 이상의 버전 구성 요소가 있습니다.
하나 이상의 구성 요소가 input 0보다 작습니다.
하나 이상의 구성 요소가 input 정수가 아닙니다.
하나 input 이상의 구성 요소가 Int32.MaxValue보다 큰 숫자를 나타냅니다.
설명
매개 변수는 input 다음 형식이어야 합니다.
major.minor[.build[.revision]]
여기서major는 minor주 버전 번호, buildrevision 부 버전 번호, 빌드 번호 및 수정 번호 등 버전 번호의 네 가지 구성 요소에 대한 문자열 표현입니다. 선택적 구성 요소는 대괄호([ 및 ])로 표시됩니다. 구성 요소는 지정된 순서로 표시되어야 하며 마침표로 구분해야 합니다.
적용 대상
Parse(String)
- Source:
- Version.cs
- Source:
- Version.cs
- Source:
- Version.cs
- Source:
- Version.cs
- Source:
- Version.cs
버전 번호의 문자열 표현을 해당하는 Version 개체로 변환합니다.
public:
static Version ^ Parse(System::String ^ input);
public static Version Parse(string input);
static member Parse : string -> Version
Public Shared Function Parse (input As String) As Version
매개 변수
- input
- String
변환할 버전 번호를 포함하는 문자열입니다.
반품
매개 변수에 지정된 input 버전 번호와 동일한 개체입니다.
예외
input은 null입니다.
input 에는 2개 또는 4개 이상의 버전 구성 요소가 있습니다.
하나 이상의 구성 요소가 input 0보다 작습니다.
하나 이상의 구성 요소가 input 정수가 아닙니다.
하나 input 이상의 구성 요소가 Int32.MaxValue보다 큰 숫자를 나타냅니다.
예제
다음 예제에서는 이 메서드를 Parse 사용하여 버전 정보가 포함된 여러 문자열을 구문 분석합니다.
using System;
public class Example
{
public static void Main()
{
string input = "4.0";
ParseVersion(input);
input = "4.0.";
ParseVersion(input);
input = "1.1.2";
ParseVersion(input);
input = "1.1.2.01702";
ParseVersion(input);
input = "1.1.2.0702.119";
ParseVersion(input);
input = "1.3.5.2150000000";
ParseVersion(input);
}
private static void ParseVersion(string input)
{
try {
Version ver = Version.Parse(input);
Console.WriteLine("Converted '{0} to {1}.", input, ver);
}
catch (ArgumentNullException) {
Console.WriteLine("Error: String to be parsed is null.");
}
catch (ArgumentOutOfRangeException) {
Console.WriteLine("Error: Negative value in '{0}'.", input);
}
catch (ArgumentException) {
Console.WriteLine("Error: Bad number of components in '{0}'.",
input);
}
catch (FormatException) {
Console.WriteLine("Error: Non-integer value in '{0}'.", input);
}
catch (OverflowException) {
Console.WriteLine("Error: Number out of range in '{0}'.", input);
}
}
}
// The example displays the following output:
// Converted '4.0 to 4.0.
// Error: Non-integer value in '4.0.'.
// Converted '1.1.2 to 1.1.2.
// Converted '1.1.2.01702 to 1.1.2.1702.
// Error: Bad number of components in '1.1.2.0702.119'.
// Error: Number out of range in '1.3.5.2150000000'.
open System
let parseVersion (input: string) =
try
let ver = Version.Parse input
printfn $"Converted '{input} to {ver}."
with
| :? ArgumentNullException ->
printfn "Error: String to be parsed is null."
| :? ArgumentOutOfRangeException ->
printfn $"Error: Negative value in '{input}'."
| :? ArgumentException ->
printfn $"Error: Bad number of components in '{input}'."
| :? FormatException ->
printfn $"Error: Non-integer value in '{input}'."
| :? OverflowException ->
printfn $"Error: Number out of range in '{input}'."
[<EntryPoint>]
let main _ =
let input = "4.0"
parseVersion input
let input = "4.0."
parseVersion input
let input = "1.1.2"
parseVersion input
let input = "1.1.2.01702"
parseVersion input
let input = "1.1.2.0702.119"
parseVersion input
let input = "1.3.5.2150000000"
parseVersion input
0
// The example displays the following output:
// Converted '4.0 to 4.0.
// Error: Non-integer value in '4.0.'.
// Converted '1.1.2 to 1.1.2.
// Converted '1.1.2.01702 to 1.1.2.1702.
// Error: Bad number of components in '1.1.2.0702.119'.
// Error: Number out of range in '1.3.5.2150000000'.
Module Example
Public Sub Main()
Dim input As String = "4.0"
ParseVersion(input)
input = "4.0."
ParseVersion(input)
input = "1.1.2"
ParseVersion(input)
input = "1.1.2.01702"
ParseVersion(input)
input = "1.1.2.0702.119"
ParseVersion(input)
input = "1.3.5.2150000000"
ParseVersion(input)
End Sub
Private Sub ParseVersion(input As String)
Try
Dim ver As Version = Version.Parse(input)
Console.WriteLine("Converted '{0} to {1}.", input, ver)
Catch e As ArgumentNullException
Console.WriteLine("Error: String to be parsed is null.")
Catch e As ArgumentOutOfRangeException
Console.WriteLine("Error: Negative value in '{0}'.", input)
Catch e As ArgumentException
Console.WriteLine("Error: Bad number of components in '{0}'.",
input)
Catch e As FormatException
Console.WriteLine("Error: Non-integer value in '{0}'.", input)
Catch e As OverflowException
Console.WriteLine("Error: Number out of range in '{0}'.", input)
End Try
End Sub
End Module
' The example displays the following output:
' Converted '4.0 to 4.0.
' Error: Non-integer value in '4.0.'.
' Converted '1.1.2 to 1.1.2.
' Converted '1.1.2.01702 to 1.1.2.1702.
' Error: Bad number of components in '1.1.2.0702.119'.
' Error: Number out of range in '1.3.5.2150000000'.
설명
매개 변수는 input 다음 형식이어야 합니다.
major.minor[.build[.revision]]
여기서major는 minor주 버전 번호, buildrevision 부 버전 번호, 빌드 번호 및 수정 번호 등 버전 번호의 네 가지 구성 요소에 대한 문자열 표현입니다. 선택적 구성 요소는 대괄호([ 및 ])로 표시됩니다. 구성 요소는 지정된 순서로 표시되어야 하며 마침표로 구분해야 합니다.
Important
버전 번호의 문자열 표현은 인식된 패턴을 준수해야 하므로 애플리케이션은 사용자 입력을 구문 분석하기 위해 메서드를 호출 Parse 할 때 항상 예외 처리를 사용해야 합니다. 또는 메서드를 TryParse 호출하여 버전 번호의 문자열 표현을 구문 분석하고 구문 분석 작업이 성공했는지 여부를 나타내는 값을 반환할 수 있습니다.
이 Parse 메서드는 편리한 메서드이며 생성자를 호출하는 Version(String) 것과 같습니다.