다음은 C#의 단항 연산자입니다. −
+ - ! ~ ++ -- (type)* & sizeof
sizeof 연산자에 대해 알아보자. sizeof는 데이터 유형의 크기를 반환합니다.
int 데이터 유형의 크기를 찾아야 한다고 가정해 봅시다 -
sizeof(int)
이중 데이터 유형의 경우 -
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