Version::TryParse Method (String^, Version^%)


The .NET API Reference documentation has a new home. Visit the .NET API Browser on to see the new experience.

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.

Namespace:   System
Assembly:  mscorlib (in mscorlib.dll)

static bool TryParse(
	String^ input,
	[OutAttribute] Version^% result


Type: System::String^

A string that contains a version number to convert.

Type: System::Version^%

When this method returns, contains the Version equivalent of the number that is contained in input, if the conversion succeeded, or a Version object whose major and minor version numbers are 0 if the conversion failed. If input is null or String::Empty, result is null when the method returns.

Return Value

Type: System::Boolean

true if the input parameter was converted successfully; otherwise, false.

The TryParse method is similar to the Parse method, except that it does not throw an exception if the conversion fails. 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.

For the parse operation to succeed, the input parameter must be in the following format:


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. Optional components are shown in square brackets ([ and ]). The components must appear in order, and must be separated by periods.

The following example uses the TryParse method to parse a number of strings that contain version information.

No code example is currently available or this language may not be supported.

Universal Windows Platform
Available since 8
.NET Framework
Available since 4.0
Portable Class Library
Supported in: portable .NET platforms
Available since 4.0
Windows Phone Silverlight
Available since 7.1
Windows Phone
Available since 8.1
Return to top