Posts

  C# - Type Conversion (Type Casting) Type conversion in C# means converting one data type into another. It is also known as type casting . There are mainly two types of type casting in C#: implicit type conversion and explicit type conversion . 1. Implicit Type Conversion Implicit type conversion is automatically handled by the C# compiler. It happens when the conversion is safe and no data will be lost. This usually includes conversions from a smaller data type to a larger data type, such as from int to double , or from a derived class to a base class. For example: If we have an integer variable a with value 9 , and we assign it to a double variable b , the compiler automatically converts it. int a = 9; double b = a; Here, a is automatically converted to a double type. When we print both values using Console.WriteLine , the output will be: 9 9   2. Explicit Type Conversion Explicit type conversion, also known as manual casting, is done by the pro...
Recent posts