What is the cast operator () in C#?

WBOY
Release: 2023-08-31 12:05:02
forward
1320 people have browsed it

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();
      }
   }
}
Copy after login

To convert double to int, we perform an explicit type conversion-

x = (int)a;
Copy after login

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!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!