Back to course

Type Casting and Conversion

.NET Zero to Hero: Master C# and Modern App Development

Converting Data Types

Sometimes you need to change a value from one type to another.

1. Implicit Casting (Automatic)

Converting smaller types to larger ones (e.g., int to double).

2. Explicit Casting (Manual)

Converting larger types to smaller ones. csharp double myDouble = 9.78; int myInt = (int)myDouble; // Manual casting: 9

3. Conversion Classes

Using Convert class or Parse method: csharp string input = "45"; int age = int.Parse(input);