C# 中的一元運算子是什麼?
以下是 C# 中的一元運算子 −
+ - ! ~ ++ -- (type)* & sizeof
讓我們瞭解一下 sizeof 運算子。sizeof 返回資料型別的尺寸。
假設您需要查詢 int 資料型別的尺寸 −
sizeof(int)
對於 double 資料型別 −
sizeof(double)
讓我們看一個完整的示例來查詢各種資料型別的尺寸 −
示例
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();
}
}
}輸出
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
廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP