Computer >> Máy Tính >  >> Lập trình >> C#

Toán tử một ngôi trong C # là gì?

Sau đây là các toán tử một ngôi trong C # -

+ - ! ~ ++ -- (type)* & sizeof

Hãy để chúng tôi tìm hiểu về toán tử sizeof. Sizeof trả về kích thước của kiểu dữ liệu.

Giả sử bạn cần tìm kích thước của kiểu dữ liệu int -

sizeof(int)

Đối với kiểu dữ liệu kép -

sizeof(double)

Hãy để chúng tôi xem ví dụ đầy đủ để tìm kích thước của các kiểu dữ liệu khác nhau -

Ví dụ

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

Đầu ra

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