using System;
class Parse {
/// <summary>
/// Example of various Parse methods
/// </summary>
private static void Main() {
//all the types in .Net have a Parse method
int i = int.Parse("34");
bool b = bool.Parse("true");
double d = double.Parse("234.333");
DateTime dateTime = DateTime.Parse("2008-03-02 12:20am");
//TryParse will return false if the parsing fails
int intvalue;
bool ok = int.TryParse("42", out intvalue); //ok = True, intvalue = 42
ok = int.TryParse("abc", out intvalue); //ok = False, intvalue = 0
//ParseExtact takes a format
DateTime dt = DateTime.ParseExact("02-03-2008", "dd-MM-yyyy",
System.Globalization.CultureInfo.CurrentCulture); //dt = 3/2/2008 12:00:00 AM
Console.Out.WriteLine("dt = " + dt);
Console.In.ReadLine();
}
}
//csharp/4828