Type Casting in C# — a practical guide to C# type casting with clear examples you can reuse in real projects.
C# Tutorial Series (16/121). Prefer one article? Read the complete C# tutorial.
Short description
Prefer pattern matching `is` checks over risky casts.
Casting
double d = 3.7;
int n = (int)d; // 3
if (obj is string s) Console.WriteLine(s);