Type Conversion
Implicit conversions widen safely, explicit casts narrow and Convert, Parse and TryParse handle text.
Example
int i = 9;
double d = i;
int n = (int)3.99;
int p = int.Parse("42");
bool ok = int.TryParse("x", out int q);
Console.WriteLine($"{d} {n} {p} {ok} {q}");Exercise
Safe parse.
int.("5", out int n)
Quiz Test
These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.