C# Type Casting
We need to convert data of one type to another type before it is used in arithmetic operations that are called Type Conversion or Type Casting.
In C#, type casting is two types:
Implicit Conversions can always be performed without any loss of data.
short y=50; int x=y; // Implicit Conversions
There are many conversions that can’t be implicitly made between types. If we attempt such conversions, the compiler will give an error message. We can explicitly carry out such conversions using the ‘cast’ operator. This process is known as Explicit Conversions. It has the following syntax:
type variable1=(type) variable2;
float x=3.14; int y=(int)x;