What is Cast Operator () in C#?

CsharpProgrammingServer Side Programming

Type conversion is converting one type of data to another type. Explicit conversions are done explicitly by users using the pre-defined functions and require a cast operator.

Let us see an example to cast double to int −

Example

using System;

namespace Demo {

   class Program {

      static void Main(string[] args) {
         double a = 4563.56;
         int x;

         x = (int)a;
         Console.WriteLine(x);
         Console.ReadKey();
      }
   }
}

To cast double to int, we perfomed explicit type casting −

x = (int)a;
raja
Published on 14-Aug-2018 07:54:01
Advertisements