0Pricing
C# Academy · Lesson

Converting Between Numbers

Casts and Convert methods.

Why Convert?

Different numeric types can't always mix freely. Sometimes you must convert a value from one type to another.

C# offers implicit conversions, explicit casts, the Convert class, and parsing from text. This lesson covers each.

Implicit Conversion

When the target type can hold every possible value of the source, C# converts implicitly with no extra syntax.

An int fits inside a double, so this assignment is automatic and safe.

int whole = 7;
double real = whole;
Console.WriteLine(real);

All lessons in this course

  1. Numeric Types
  2. Arithmetic and Precedence
  3. The Math Class
  4. Converting Between Numbers
← Back to C# Academy