When We assign a value of one datatype to another datatype.
There are two types of casting
Implicit Casting
Implicit casting is done automatically when passing a smaller size type to a larger size type:
int myInt = 9;
double myDouble = myInt;
Console.WriteLine(myInt);
Console.WriteLine(myDouble)
Explicit Casting
Explicit casting must be done manually by placing the type in parentheses in front of the value
double myDouble = 9.78;
int myInt = (int) myDouble;
Console.WriteLine(myDouble);
Console.WriteLine(myInt);
Type Conversion Methods
int myInt = 10;
double myDouble = 5.25;
bool myBool = true;
Console.WriteLine(Convert.ToString(myInt));
Console.WriteLine(Convert.ToDouble(myInt));
Console.WriteLine(Convert.ToInt32(myDouble));
Console.WriteLine(Convert.ToString(myBool));