在C# 中,单个字节用于存储 8 位值。字节和为sbyte b OTH用于字节类型的数据。
字节 :这个Struct用于表示8位无符号整数。 byte 是不可变值类型,Byte 的范围是 0 到 255。
例子 :
C#
// C# program to demonstrate
// the byte Struct Fields
using System;
using System.Text;
public class GFG{
// Main Method
static void Main(string[] args)
{
// printing minimum & maximum values
Console.WriteLine("Minimum value of byte: " + byte.MinValue);
Console.WriteLine("Maximum value of byte: " + byte.MaxValue);
}
}
C#
// C# program to demonstrate
// the sbyte Struct Fields
using System;
using System.Text;
public class GFG{
// Main Method
static void Main(string[] args)
{
// printing minimum & maximum values
Console.WriteLine("Minimum value of sbyte: " + sbyte.MinValue);
Console.WriteLine("Maximum value of sbyte: " + sbyte.MaxValue);
}
}
输出:
Minimum value of byte: 0
Maximum value of byte: 255
字节 :此结构用于表示8 位有符号整数。 sbyte 代表整数,其值范围从-128 到 +127。
例子 :
C#
// C# program to demonstrate
// the sbyte Struct Fields
using System;
using System.Text;
public class GFG{
// Main Method
static void Main(string[] args)
{
// printing minimum & maximum values
Console.WriteLine("Minimum value of sbyte: " + sbyte.MinValue);
Console.WriteLine("Maximum value of sbyte: " + sbyte.MaxValue);
}
}
输出:
Minimum value of sbyte: -128
Maximum value of sbyte: 127
C#中byte和sbyte的区别
Sr.No |
BYTE |
SBYTE |
1. |
byte is used to represent 8-bit unsigned integers | sbyte is used to represent 8-bit signed integers |
2. |
byte stands for unsigned byte. | sbyte stands for unsigned byte. |
3. |
It can store positive bytes only. | It can store negative and positive bytes. |
4. |
It takes 8-bits space in the memory. | It also takes 8-bits space in the memory. |
5. |
The range of byte is from 0 to 255. | The sbyte ranges from -128 to 127 |
6. |
Syntax to declare the byte:
|
Syntax to declare the sbyte:
|