Home >Backend Development >C#.Net Tutorial >What is the cast operator () in C#?

What is the cast operator () in C#?

WBOY
WBOYforward
2023-08-31 12:05:021371browse

C# 中的强制转换运算符 () 是什么?

Type conversion is to convert one type of data into another type of data. Explicit conversion is done explicitly by the user using predefined functions and requires a cast operator.

Let us see an example of casting 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 convert double to int, we perform an explicit type conversion-

x = (int)a;

The above is the detailed content of What is the cast operator () in C#?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete