Parsing Values from String Data
The .NET data types provide the ability to generate a variable of their underlying type given a tex-
tual equivalent (e.g., parsing). This technique can be extremely helpful when you wish to convert a
bit of user input data (such as a selection from a GUI-based drop-down list box) into a numerical
value. Consider the following parsing logic within a method named ParseFromStrings():
static void ParseFromStrings()
{
Console.WriteLine("=> Data type parsing:");
bool b = bool.Parse("True");
Console.WriteLine("Value of b: {0}", b);
double d = double.Parse("99.884");
Console.WriteLine("Value of d: {0}", d);
int i = int.Parse("8");
Console.WriteLine("Value of i: {0}", i);
char c = Char.Parse("w");
Console.WriteLine("Value of c: {0}", c);
Console.WriteLine();
}
Do'stlaringiz bilan baham: |