c# 整数类型转byte_C#中数据类型的整数类型

c# 整数类型转byte

Here is the list of the built-in integral types of data types in C#, sbyte, byte, char, short, ushort, int, uint, long and ulong

这是C#, sbyte , byte , char , short , ushort , int , int , uint , long和ulong中数据类型的内置整数类型的列表

C#数据类型的积分类型 (C# Integral types of Data types)

TypeSystem typeSize (in bits)Value RangeValue type
sbyteSystem.SByte8-bits-128 to 127Signed integer
byteSystem.Byte8-bits0 to 255Unsigned integer
charSystem.Char16-bitsU+0000 to U+ffffUnicode character
shortSystem.Int1616-bits-32,768 to 32,767Signed integer
ushortSystem.Int1616-bits0 to 65,535Unsigned integer
intSystem.Int3232-bits-2,147,483,648 to 2,147,483,647Signed integer
uintSystem.Int3232-bits0 to 4,294,967,295Unsigned integer
longSystem.Int6464-bits-9,223,372,036,854,775,808 to 9,223,372,036,854,775,807Signed integer
ulongSystem.Int6464-bits0 to 18,446,744,073,709,551,615Unsigned integer
类型 系统类型 大小(以位为单位) 取值范围 值类型
兆字节 系统字节 8位 -128至127 有符号整数
字节 系统字节 8位 0至255 无符号整数
烧焦 系统字符 16位 U + 0000至U + ffff Unicode字符
System.Int16 16位 -32,768至32,767 有符号整数
超短 System.Int16 16位 0至65,535 无符号整数
整型 System.Int32 32位 -2,147,483,648至2,147,483,647 有符号整数
int System.Int32 32位 0至4,294,967,295 无符号整数
System.Int64 64位 -9,223,372,036,854,775,808至9,223,372,036,854,775,807 有符号整数
乌龙 System.Int64 64位 0至18,446,744,073,709,551,615 无符号整数

Example:

例:

In this example, we are declaring variables of different integral types of data types, initializing with the different value, printing the system types of the variables, size of the types and min, max values of the types.

在此示例中,我们声明了不同整数类型的数据类型的变量,使用不同的值进行初始化,打印了变量的系统类型,类型的大小以及类型的最小值,最大值。

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("type of variable = " + a.GetType());
            Console.WriteLine("size of sbyte = " + sizeof(sbyte));
            Console.WriteLine("Min value of sbyte = " + sbyte.MinValue);
            Console.WriteLine("Max value of sbyte = " + sbyte.MaxValue);
            Console.WriteLine();

            //byte
            byte b = 10;
            Console.WriteLine("byte...");
            Console.WriteLine("b = " + b);
            Console.WriteLine("type of variable = " + b.GetType());
            Console.WriteLine("size of byte = " + sizeof(byte));
            Console.WriteLine("Min value of byte = " + byte.MinValue);
            Console.WriteLine("Max value of byte = " + byte.MaxValue);
            Console.WriteLine();

            //char
            char c = 'P';
            Console.WriteLine("char...");
            Console.WriteLine("c = " + c);
            Console.WriteLine("type of variable = " + c.GetType());
            Console.WriteLine("size of char = " + sizeof(char));
            Console.WriteLine("Min value of char = " + (int)(char.MinValue));
            Console.WriteLine("Max value of char = " + (int)(char.MaxValue));
            Console.WriteLine();

            //short
            short d = -18910;
            Console.WriteLine("short...");
            Console.WriteLine("d = " + d);
            Console.WriteLine("type of variable = " + d.GetType());
            Console.WriteLine("size of short = " + sizeof(short));
            Console.WriteLine("Min value of short = " + short.MinValue);
            Console.WriteLine("Max value of short = " + short.MaxValue);
            Console.WriteLine();

            //ushort
            ushort e = 18910;
            Console.WriteLine("ushort...");
            Console.WriteLine("e = " + e);
            Console.WriteLine("type of variable = " + e.GetType());
            Console.WriteLine("size of ushort = " + sizeof(short));
            Console.WriteLine("Min value of ushort = " + ushort.MinValue);
            Console.WriteLine("Max value of ushort = " + ushort.MaxValue);
            Console.WriteLine();

            //int
            int f = -893818910;
            Console.WriteLine("int...");
            Console.WriteLine("f = " + f);
            Console.WriteLine("type of variable = " + f.GetType());
            Console.WriteLine("size of int = " + sizeof(int));
            Console.WriteLine("Min value of int = " + int.MinValue);
            Console.WriteLine("Max value of int = " + int.MaxValue);
            Console.WriteLine();

            //uint
            int g = 893818910;
            Console.WriteLine("uint...");
            Console.WriteLine("g = " + g);
            Console.WriteLine("type of variable = " + g.GetType());
            Console.WriteLine("size of uint = " + sizeof(uint));
            Console.WriteLine("Min value of uint = " + uint.MinValue);
            Console.WriteLine("Max value of uint = " + uint.MaxValue);
            Console.WriteLine();

            //long
            long h = -90909893818910;
            Console.WriteLine("long...");
            Console.WriteLine("h = " + h);
            Console.WriteLine("type of variable = " + h.GetType());
            Console.WriteLine("size of long = " + sizeof(long));
            Console.WriteLine("Min value of long = " + long.MinValue);
            Console.WriteLine("Max value of long = " + long.MaxValue);
            Console.WriteLine();

            //ulong
            ulong i = 90909893818910;
            Console.WriteLine("ulong...");
            Console.WriteLine("i = " + i);
            Console.WriteLine("type of variable = " + i.GetType());
            Console.WriteLine("size of ulong = " + sizeof(ulong));
            Console.WriteLine("Min value of ulong = " + ulong.MinValue);
            Console.WriteLine("Max value of ulong = " + ulong.MaxValue);
            Console.WriteLine();

            //hit ENTER to exit
            Console.ReadLine();
        }
    }
}


Output

输出量

sbyte...
a = -10
type of variable = System.SByte
size of sbyte = 1
Min value of sbyte = -128
Max value of sbyte = 127

byte...
b = 10
type of variable = System.Byte
size of byte = 1
Min value of byte = 0
Max value of byte = 255

char...
c = P
type of variable = System.Char
size of char = 2
Min value of char = 0
Max value of char = 65535

short...
d = -18910
type of variable = System.Int16
size of short = 2
Min value of short = -32768
Max value of short = 32767

ushort...
e = 18910
type of variable = System.UInt16
size of ushort = 2
Min value of ushort = 0
Max value of ushort = 65535

int...
f = -893818910
type of variable = System.Int32
size of int = 4
Min value of int = -2147483648
Max value of int = 2147483647

uint...
g = 893818910
type of variable = System.Int32
size of uint = 4
Min value of uint = 0
Max value of uint = 4294967295

long...
h = -90909893818910
type of variable = System.Int64
size of long = 8
Min value of long = -9223372036854775808
Max value of long = 9223372036854775807

ulong...
i = 90909893818910
type of variable = System.UInt64
size of ulong = 8
Min value of ulong = 0
Max value of ulong = 18446744073709551615

Ref: Integral types table

参考: 整体类型表

翻译自: https://www.includehelp.com/dot-net/integral-types-of-data-types-in-c-sharp.aspx

c# 整数类型转byte

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值