What is Cast Operator () in C#?

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 −


using System;

namespace Demo {

   class Program {

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

         x = (int)a;

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

x = (int)a;

Updated on: 21-Jun-2020


Kickstart Your Career

Get certified by completing the course

Get Started