What are unary operators in C#?

PHPz
Release: 2023-09-07 10:05:02
forward
1440 people have browsed it

C# 中什么是一元运算符?

The following are the unary operators in C# -

+ - ! ~ ++ -- (type)* & sizeof
Copy after login

Let us understand the sizeof operator. sizeof returns the size of the data type.

Suppose you need to find the size of int data type -

sizeof(int)
Copy after login

For double data type -

sizeof(double)
Copy after login

Let’s see the complete example to find the size of various data types -

Example

Real-time demonstration

using System;

namespace Demo {

   class Program {

      static void Main(string[] args) {

         Console.WriteLine("The size of int is {0}", sizeof(int));
         Console.WriteLine("The size of int is {0}", sizeof(char));
         Console.WriteLine("The size of short is {0}", sizeof(short));
         Console.WriteLine("The size of long is {0}", sizeof(long));
         Console.WriteLine("The size of double is {0}", sizeof(double));

         Console.ReadLine();
      }
   }
}
Copy after login

Output

The size of int is 4
The size of int is 2
The size of short is 2
The size of long is 8
The size of double is 8
Copy after login

The above is the detailed content of What are unary operators 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!