如何使用 sizeof() 运算符查找 C# 中的数据类型或变量的大小
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
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP