如何在C#中使用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
热门推荐
10 朋友新年祝福语大全 简短
11 新年祝福语简短大方兔年
12 搬新家礼物祝福语简短
13 同学见面花束祝福语简短
14 五一假期祝福语幽默简短
15 离职欢送敬酒祝福语简短
16 对学弟的祝福语简短
17 考老师辞职祝福语简短
18 祝福语驱散霉运的话简短