本文整理匯總了C#中System.Version.Parse方法的典型用法代碼示例。如果您正苦於以下問題:C# Version.Parse方法的具體用法?C# Version.Parse怎麽用?C# Version.Parse使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類System.Version
的用法示例。
在下文中一共展示了Version.Parse方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: Main
//引入命名空間
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);
}
}
}
輸出:
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'.