Version.TryParse Methode
Definition
Überlädt
TryParse(ReadOnlySpan<Char>, Version) |
Versucht, die angegebene schreibgeschützte Zeichenspanne einer Versionsnummer in ein entsprechendes Version-Objekt zu konvertieren, und gibt einen Wert zurück, der angibt, ob die Konvertierung erfolgreich durchgeführt wurdeTries to convert the specified read-only span of characters representing a version number to an equivalent Version object, and returns a value that indicates whether the conversion succeeded. |
TryParse(String, Version) |
Versucht, die Zeichenfolgendarstellung einer Versionsnummer in ein entsprechendes Version-Objekt zu konvertieren, und gibt einen Wert zurück, der angibt, ob die Konvertierung erfolgreich durchgeführt wurde.Tries to convert the string representation of a version number to an equivalent Version object, and returns a value that indicates whether the conversion succeeded. |
TryParse(ReadOnlySpan<Char>, Version)
Versucht, die angegebene schreibgeschützte Zeichenspanne einer Versionsnummer in ein entsprechendes Version-Objekt zu konvertieren, und gibt einen Wert zurück, der angibt, ob die Konvertierung erfolgreich durchgeführt wurdeTries to convert the specified read-only span of characters representing a version number to an equivalent Version object, and returns a value that indicates whether the conversion succeeded.
public:
static bool TryParse(ReadOnlySpan<char> input, [Runtime::InteropServices::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
Parameter
- input
- ReadOnlySpan<Char>
Eine schreibgeschützte Spanne von Zeichen, die eine zu konvertierende Versionsnummer enthältA read-only span of characters that contains a version number to convert.
- result
- Version
Enthält nach dem Beenden dieser Methode die Version-Entsprechung der Zahl in input
, wenn die Konvertierung erfolgreich warWhen this method returns, the Version equivalent of the number that is contained in input
, if the conversion succeeded. Wenn input
null
oder Empty ist oder, wenn bei der Konvertierung ein Fehler auftritt, dann ist result
null
, wenn die Methode zurückgegeben wird.If input
is null
, Empty, or if the conversion fails, result
is null
when the method returns.
Gibt zurück
true
, wenn der input
-Parameter erfolgreich konvertiert wurde, andernfalls false
.true
if the input
parameter was converted successfully; otherwise, false
.
Hinweise
Die TryParse
-Methode ähnelt der Parse-Methode, mit der Ausnahme, dass keine Ausnahme ausgelöst wird, wenn bei der Konvertierung ein Fehler auftritt.The TryParse
method is similar to the Parse method, except that it doesn't throw an exception if the conversion fails. Stattdessen wird false
zurückgegeben, wenn input
null
ist, weniger als zwei oder mehr als vier Komponenten aufweist, mindestens eine Komponente aufweist, die keine ganze Zahl ist, mindestens eine Komponente kleiner als 0 (null) ist oder mindestens eine Komponente größer als Int32.MaxValue ist.Instead, it returns false
if input
is null
, has fewer than two or more than four components, has at least one component that is not an integer, has at least one component that is less than zero, or has at least one component that is greater than Int32.MaxValue.
Damit der Analyse Vorgang erfolgreich ausgeführt werden kann, muss der Parameter "input
" das folgende Format aufweisen:For the parse operation to succeed, the input
parameter must be in the following format:
major.minor[.build[.revision]]
Dabei sind major
, minor
, build
und revision
die Zeichen folgen Darstellungen der vier Komponenten der Versionsnummer: Hauptversionsnummer, neben Versionsnummer, Buildnummer und Revisionsnummer.where major
, minor
, build
, and revision
are the string representations of the version number's four components: major version number, minor version number, build number, and revision number, respectively. Optionale Komponenten werden in eckigen Klammern ([und]) angezeigt.Optional components are shown in square brackets ([ and ]). Die Komponenten müssen in der richtigen Reihenfolge angezeigt werden und müssen durch Zeiträume getrennt werden.The components must appear in order and must be separated by periods.
TryParse(String, Version)
Versucht, die Zeichenfolgendarstellung einer Versionsnummer in ein entsprechendes Version-Objekt zu konvertieren, und gibt einen Wert zurück, der angibt, ob die Konvertierung erfolgreich durchgeführt wurde.Tries to convert the string representation of a version number to an equivalent Version object, and returns a value that indicates whether the conversion succeeded.
public:
static bool TryParse(System::String ^ input, [Runtime::InteropServices::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
Parameter
- input
- String
Eine Zeichenfolge, die eine zu konvertierende Versionsnummer enthält.A string that contains a version number to convert.
- result
- Version
Enthält nach dem Beenden dieser Methode die Version-Entsprechung der Zahl in input
, wenn die Konvertierung erfolgreich war.When this method returns, contains the Version equivalent of the number that is contained in input
, if the conversion succeeded. Wenn input
null
oder Empty ist oder, wenn bei der Konvertierung ein Fehler auftritt, dann ist result
null
, wenn die Methode zurückgegeben wird.If input
is null
, Empty, or if the conversion fails, result
is null
when the method returns.
Gibt zurück
true
, wenn der input
-Parameter erfolgreich konvertiert wurde, andernfalls false
.true
if the input
parameter was converted successfully; otherwise, false
.
Beispiele
Im folgenden Beispiel wird die TryParse-Methode verwendet, um eine Reihe von Zeichen folgen zu analysieren, die Versionsinformationen enthalten.The following example uses the TryParse method to parse a number of strings that contain version information.
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'.
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'.
Hinweise
Die TryParse
-Methode ähnelt der Parse-Methode, mit der Ausnahme, dass keine Ausnahme ausgelöst wird, wenn bei der Konvertierung ein Fehler auftritt.The TryParse
method is similar to the Parse method, except that it doesn't throw an exception if the conversion fails. Stattdessen wird false
zurückgegeben, wenn input
null
ist, weniger als zwei oder mehr als vier Komponenten aufweist, mindestens eine Komponente aufweist, die keine ganze Zahl ist, mindestens eine Komponente kleiner als 0 (null) ist oder mindestens eine Komponente größer als Int32.MaxValue ist.Instead, it returns false
if input
is null
, has fewer than two or more than four components, has at least one component that is not an integer, has at least one component that is less than zero, or has at least one component that is greater than Int32.MaxValue.
Damit der Analyse Vorgang erfolgreich ausgeführt werden kann, muss der Parameter "input
" das folgende Format aufweisen:For the parse operation to succeed, the input
parameter must be in the following format:
major.minor[.build[.revision]]
Dabei sind major
, minor
, build
und revision
die Zeichen folgen Darstellungen der vier Komponenten der Versionsnummer: Hauptversionsnummer, neben Versionsnummer, Buildnummer und Revisionsnummer.where major
, minor
, build
, and revision
are the string representations of the version number's four components: major version number, minor version number, build number, and revision number, respectively. Optionale Komponenten werden in eckigen Klammern ([und]) angezeigt.Optional components are shown in square brackets ([ and ]). Die Komponenten müssen in der richtigen Reihenfolge angezeigt werden und müssen durch Zeiträume getrennt werden.The components must appear in order and must be separated by periods.