Locked lesson.
About this lesson
We examine the process for Type Conversion and Casting.
Exercise files
Download this lesson’s related exercise files.
20 - Type Conversion Casting.docx61 KB 20 - Type Conversion Casting SOLUTION.docx
58 KB
Quick reference
Type Conversion/Casting
Type casting allows you to convert different number data types into one another.
When to use
Use this whenever you need to convert one number data type into another.
Instructions
float floatNumber = 5.2f;
int intNumber;
Convert.ToInt32(floatNumber); // Rounds
intNumber = (int)floatNumber; // Doesn't round
Hints & tips
- Convert.ToInt32(floatNumber);
- intNumber = (int)floatNumber;
Lesson notes are only available for subscribers.