这是C#,sbyte,byte,char,short,ushort,int,uint,long和ulong中数据类型的内置整数类型的列表
类型 | 系统类型 | 大小(以位为单位) | 取值范围 | 值类型 |
---|---|---|---|---|
sbyte | System.SByte | 8位 | -128至127 | 有符号整数 |
byte | System.Byte | 8位 | 0至255 | 无符号整数 |
char | System.Char | 16位 | U + 0000至U + ffff | Unicode字符 |
short | System.Int16 | 16位 | -32,768至32,767 | 有符号整数 |
ushort | System.Int16 | 16位 | 0至65,535 | 无符号整数 |
int | System.Int32 | 32位 | -2,147,483,648至2,147,483,647 | 有符号整数 |
uint | System.Int32 | 32位 | 0至4,294,967,295 | 无符号整数 |
long | System.Int64 | 64位 | -9,223,372,036,854,775,808至9,223,372,036,854,775,807 | 有符号整数 |
ulong | System.Int64 | 64位 | 0至18,446,744,073,709,551,615 | 无符号整数 |
示例
在此示例中,我们声明了不同整数类型的数据类型的变量,使用不同的值进行初始化,打印了变量的系统类型,类型的大小以及类型的最小值,最大值。
using System; using System.Text; namespace Test { class Program { static void Main(string[] args) { //sbyte sbyte a = -10; Console.WriteLine("sbyte..."); Console.WriteLine("a = " + a); Console.WriteLine("变量类型 = " + a.GetType()); Console.WriteLine("大小 sbyte = " + sizeof(sbyte)); Console.WriteLine("最小值 sbyte = " + sbyte.MinValue); Console.WriteLine("最大值 sbyte = " + sbyte.MaxValue); Console.WriteLine(); //byte byte b = 10; Console.WriteLine("byte..."); Console.WriteLine("b = " + b); Console.WriteLine("变量类型 = " + b.GetType()); Console.WriteLine("大小 byte = " + sizeof(byte)); Console.WriteLine("最小值 byte = " + byte.MinValue); Console.WriteLine("最大值 byte = " + byte.MaxValue); Console.WriteLine(); //char char c = 'P'; Console.WriteLine("char..."); Console.WriteLine("c = " + c); Console.WriteLine("变量类型 = " + c.GetType()); Console.WriteLine("大小 char = " + sizeof(char)); Console.WriteLine("最小值 char = " + (int)(char.MinValue)); Console.WriteLine("最大值 char = " + (int)(char.MaxValue)); Console.WriteLine(); //short short d = -18910; Console.WriteLine("short..."); Console.WriteLine("d = " + d); Console.WriteLine("变量类型 = " + d.GetType()); Console.WriteLine("大小 short = " + sizeof(short)); Console.WriteLine("最小值 short = " + short.MinValue); Console.WriteLine("最大值 short = " + short.MaxValue); Console.WriteLine(); //ushort ushort e = 18910; Console.WriteLine("ushort..."); Console.WriteLine("e = " + e); Console.WriteLine("变量类型 = " + e.GetType()); Console.WriteLine("大小 ushort = " + sizeof(short)); Console.WriteLine("最小值 ushort = " + ushort.MinValue); Console.WriteLine("最大值 ushort = " + ushort.MaxValue); Console.WriteLine(); //int int f = -893818910; Console.WriteLine("int..."); Console.WriteLine("f = " + f); Console.WriteLine("变量类型 = " + f.GetType()); Console.WriteLine("大小 int = " + sizeof(int)); Console.WriteLine("最小值 int = " + int.MinValue); Console.WriteLine("最大值 int = " + int.MaxValue); Console.WriteLine(); //uint int g = 893818910; Console.WriteLine("uint..."); Console.WriteLine("g = " + g); Console.WriteLine("变量类型 = " + g.GetType()); Console.WriteLine("大小 uint = " + sizeof(uint)); Console.WriteLine("最小值 uint = " + uint.MinValue); Console.WriteLine("最大值 uint = " + uint.MaxValue); Console.WriteLine(); //long long h = -90909893818910; Console.WriteLine("long..."); Console.WriteLine("h = " + h); Console.WriteLine("变量类型 = " + h.GetType()); Console.WriteLine("大小 long = " + sizeof(long)); Console.WriteLine("最小值 long = " + long.MinValue); Console.WriteLine("最大值 long = " + long.MaxValue); Console.WriteLine(); //ulong ulong i = 90909893818910; Console.WriteLine("ulong..."); Console.WriteLine("i = " + i); Console.WriteLine("变量类型 = " + i.GetType()); Console.WriteLine("大小 ulong = " + sizeof(ulong)); Console.WriteLine("最小值 ulong = " + ulong.MinValue); Console.WriteLine("最大值 ulong = " + ulong.MaxValue); Console.WriteLine(); //按ENTER退出 Console.ReadLine(); } } }
输出结果:
sbyte... a = -10 变量类型 = System.SByte 大小 sbyte = 1 最小值 sbyte = -128 最大值 sbyte = 127 byte... b = 10 变量类型 = System.Byte 大小 byte = 1 最小值 byte = 0 最大值 byte = 255 char... c = P 变量类型 = System.Char 大小 char = 2 最小值 char = 0 最大值 char = 65535 short... d = -18910 变量类型 = System.Int16 大小 short = 2 最小值 short = -32768 最大值 short = 32767 ushort... e = 18910 变量类型 = System.UInt16 大小 ushort = 2 最小值 ushort = 0 最大值 ushort = 65535 int... f = -893818910 变量类型 = System.Int32 大小 int = 4 最小值 int = -2147483648 最大值 int = 2147483647 uint... g = 893818910 变量类型 = System.Int32 大小 uint = 4 最小值 uint = 0 最大值 uint = 4294967295 long... h = -90909893818910 变量类型 = System.Int64 大小 long = 8 最小值 long = -9223372036854775808 最大值 long = 9223372036854775807 ulong... i = 90909893818910 变量类型 = System.UInt64 大小 ulong = 8 最小值 ulong = 0 最大值 ulong = 18446744073709551615