using System;
public class Test
{
public static void Main()
{
// Convertir números en base 10: Parse y TryParse
double d = double.Parse("5.0");
Console.WriteLine (d);
int i;
bool ok = int.TryParse("5", out i);
Console.WriteLine (ok);
// Conversión a partir de una base numérica distinta: 2, 8, o 16
int j = Convert.ToInt32("1E", 16);
Console.WriteLine (j);
// Formato hexadecimal: ToString
string hex = 45.ToString("X");
Console.WriteLine (hex);
// Conversión numérica sin pérdidas:
int k = 23;
double e = k;
Console.WriteLine (e);
// Conversión numérica truncada:
double f = 23.5;
int l = (int) f;
Console.WriteLine (l);
// Conversión numérica redondeada (real a entero): Convert.ToIntegral
double g = 23.5;
int m = Convert.ToInt32(g);
Console.WriteLine (m);
}
}
dXNpbmcgU3lzdGVtOwoKcHVibGljIGNsYXNzIFRlc3QKewoJcHVibGljIHN0YXRpYyB2b2lkIE1haW4oKQoJewoJCS8vIENvbnZlcnRpciBuw7ptZXJvcyBlbiBiYXNlIDEwOiBQYXJzZSB5IFRyeVBhcnNlIAoJCWRvdWJsZSBkID0gZG91YmxlLlBhcnNlKCI1LjAiKTsKCQlDb25zb2xlLldyaXRlTGluZSAoZCk7CgkJCgkJaW50IGk7CgkJYm9vbCBvayA9IGludC5UcnlQYXJzZSgiNSIsIG91dCBpKTsKCQlDb25zb2xlLldyaXRlTGluZSAob2spOwoJCQoJCS8vIENvbnZlcnNpw7NuIGEgcGFydGlyIGRlIHVuYSBiYXNlIG51bcOpcmljYSBkaXN0aW50YTogMiwgOCwgbyAxNiAKCQlpbnQgaiA9IENvbnZlcnQuVG9JbnQzMigiMUUiLCAxNik7CgkJQ29uc29sZS5Xcml0ZUxpbmUgKGopOwoJCQoJCS8vIEZvcm1hdG8gaGV4YWRlY2ltYWw6IFRvU3RyaW5nIAoJCXN0cmluZyBoZXggPSA0NS5Ub1N0cmluZygiWCIpOwoJCUNvbnNvbGUuV3JpdGVMaW5lIChoZXgpOwoJCQoJCS8vIENvbnZlcnNpw7NuIG51bcOpcmljYSBzaW4gcMOpcmRpZGF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