Updated on Kisan Patel
Converting one type of variable to another is called casting.
C# supports two kinds of type conversions.
using System; namespace ConsoleApp { class CastingDemo { static void Main(string[] args) { int num1 = 123; long num2 = num1; Console.WriteLine(num1.ToString()); Console.WriteLine(num2.ToString()); } } }
Output of the above c# program…
using System; namespace ConsoleApp { class CastingDemo { static void Main(string[] args) { double num1 = 5.4458; int num2 = (int)num1; Console.WriteLine(num1.ToString()); Console.WriteLine(num2.ToString()); } } }
Output of the above c# program…