Version.TryParse 메서드

정의

오버로드

TryParse(String, Version)

버전 번호의 문자열 표현을 해당하는 Version 개체로 변환하려고 시도하고, 변환에 성공했는지 여부를 나타내는 값을 반환합니다.

TryParse(ReadOnlySpan<Char>, Version)

동등한 Version 개체에 대해 버전 번호를 나타내는 지정된 문자의 읽기 전용 범위를 변환하려고 시도하고, 변환에 성공했는지 여부를 나타내는 값을 반환합니다.

TryParse(String, Version)

버전 번호의 문자열 표현을 해당하는 Version 개체로 변환하려고 시도하고, 변환에 성공했는지 여부를 나타내는 값을 반환합니다.

public:
 static bool TryParse(System::String ^ input, [Runtime::InteropServices::Out] Version ^ % result);
public static bool TryParse (string input, out Version result);
public static bool TryParse (string? input, out Version? result);
static member TryParse : string * Version -> bool
Public Shared Function TryParse (input As String, ByRef result As Version) As Boolean

매개 변수

input
String

변환할 버전 번호가 들어 있는 문자열입니다.

result
Version

이 메서드가 반환되면 변환에 성공한 경우 input에 포함된 숫자에 해당하는 Version이 포함됩니다. inputnull인 경우 Empty이거나 변환에 실패하는 경우 메서드가 반환되면 resultnull입니다.

반환

true 매개 변수가 변환되었으면 input이고, 그렇지 않으면 false입니다.

예제

다음 예제에서는 메서드를 TryParse 사용하여 버전 정보가 포함된 여러 문자열을 구문 분석합니다.

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)
   {
      Version ver = null;
      if (Version.TryParse(input, out ver))
         Console.WriteLine("Converted '{0} to {1}.", input, ver);
      else
         Console.WriteLine("Unable to determine the version from '{0}'.",
                           input);
   }
}
// The example displays the following output:
//       Converted '4.0 to 4.0.
//       Unable to determine the version from '4.0.'.
//       Converted '1.1.2 to 1.1.2.
//       Converted '1.1.2.01702 to 1.1.2.1702.
//       Unable to determine the version from '1.1.2.0702.119'.
//       Unable to determine the version from '1.3.5.2150000000'.
open System

let parseVersion (input: string) =
    match Version.TryParse input with
    | true, ver ->
        printfn $"Converted '{input} to {ver}."
    | _ ->
        printfn $"Unable to determine the version from '{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.
//       Unable to determine the version from '4.0.'.
//       Converted '1.1.2 to 1.1.2.
//       Converted '1.1.2.01702 to 1.1.2.1702.
//       Unable to determine the version from '1.1.2.0702.119'.
//       Unable to determine the version from '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)
      Dim ver As Version = Nothing
      If Version.TryParse(input, ver) Then
         Console.WriteLine("Converted '{0} to {1}.", input, ver)
      Else
         Console.WriteLine("Unable to determine the version from '{0}'.",
                           input)
      End If
   End Sub
End Module
' The example displays the following output:
'       Converted '4.0 to 4.0.
'       Unable to determine the version from '4.0.'.
'       Converted '1.1.2 to 1.1.2.
'       Converted '1.1.2.01702 to 1.1.2.1702.
'       Unable to determine the version from '1.1.2.0702.119'.
'       Unable to determine the version from '1.3.5.2150000000'.

설명

TryParse 메서드는 변환이 Parse 실패할 경우 예외를 throw하지 않는다는 점을 제외하고 메서드와 유사합니다. 대신 가 null2개 또는 4개보다 작은 구성 요소가 있거나, 정수가 아니거나, 0보다 작은 구성 요소가 하나 이상 있거나, 보다 Int32.MaxValue큰 구성 요소가 하나 이상 있는 경우 input 를 반환 false 합니다.

구문 분석 작업이 성공하려면 매개 변수가 input 다음 형식이어야 합니다.

major.minor[.build[.revision]]

여기서 major, minor, buildrevision 는 버전 번호의 네 가지 구성 요소인 주 버전 번호, 부 버전 번호, 빌드 번호 및 수정 번호의 문자열 표현입니다. 선택적 구성 요소는 대괄호([ 및 ])로 표시됩니다. 구성 요소는 순서대로 표시되어야 하며 마침표로 구분해야 합니다.

추가 정보

적용 대상

TryParse(ReadOnlySpan<Char>, Version)

동등한 Version 개체에 대해 버전 번호를 나타내는 지정된 문자의 읽기 전용 범위를 변환하려고 시도하고, 변환에 성공했는지 여부를 나타내는 값을 반환합니다.

public:
 static bool TryParse(ReadOnlySpan<char> input, [Runtime::InteropServices::Out] Version ^ % result);
public static bool TryParse (ReadOnlySpan<char> input, out Version? result);
public static bool TryParse (ReadOnlySpan<char> input, out Version result);
static member TryParse : ReadOnlySpan<char> * Version -> bool
Public Shared Function TryParse (input As ReadOnlySpan(Of Char), ByRef result As Version) As Boolean

매개 변수

input
ReadOnlySpan<Char>

변환할 버전 번호가 포함된 문자의 읽기 전용 범위입니다.

result
Version

이 메서드가 반환되면 변환에 성공한 경우 input에 포함된 숫자에 해당하는 Version이 포함됩니다. inputnull인 경우 Empty이거나 변환에 실패하는 경우 메서드가 반환되면 resultnull입니다.

반환

true 매개 변수가 변환되었으면 input이고, 그렇지 않으면 false입니다.

설명

TryParse 메서드는 변환이 Parse 실패할 경우 예외를 throw하지 않는다는 점을 제외하고 메서드와 유사합니다. 대신 가 null2개 또는 4개보다 작은 구성 요소가 있거나, 정수가 아니거나, 0보다 작은 구성 요소가 하나 이상 있거나, 보다 Int32.MaxValue큰 구성 요소가 하나 이상 있는 경우 input 를 반환 false 합니다.

구문 분석 작업이 성공하려면 매개 변수가 input 다음 형식이어야 합니다.

major.minor[.build[.revision]]

여기서 major, minor, buildrevision 는 버전 번호의 네 가지 구성 요소인 주 버전 번호, 부 버전 번호, 빌드 번호 및 수정 번호의 문자열 표현입니다. 선택적 구성 요소는 대괄호([ 및 ])로 표시됩니다. 구성 요소는 순서대로 표시되어야 하며 마침표로 구분해야 합니다.

적용 대상