Byte 结构

定义

表示一个 8 位无符号整数。

public value class System::Byte : IComparable, IComparable<System::Byte>, IConvertible, IEquatable<System::Byte>, IFormattable
public value class System::Byte : IComparable, IComparable<System::Byte>, IConvertible, IEquatable<System::Byte>, ISpanFormattable
public value class System::Byte : IComparable<System::Byte>, IConvertible, IEquatable<System::Byte>, IParsable<System::Byte>, ISpanParsable<System::Byte>, System::Numerics::IAdditionOperators<System::Byte, System::Byte, System::Byte>, System::Numerics::IAdditiveIdentity<System::Byte, System::Byte>, System::Numerics::IBinaryInteger<System::Byte>, System::Numerics::IBinaryNumber<System::Byte>, System::Numerics::IBitwiseOperators<System::Byte, System::Byte, System::Byte>, System::Numerics::IComparisonOperators<System::Byte, System::Byte, bool>, System::Numerics::IDecrementOperators<System::Byte>, System::Numerics::IDivisionOperators<System::Byte, System::Byte, System::Byte>, System::Numerics::IEqualityOperators<System::Byte, System::Byte, bool>, System::Numerics::IIncrementOperators<System::Byte>, System::Numerics::IMinMaxValue<System::Byte>, System::Numerics::IModulusOperators<System::Byte, System::Byte, System::Byte>, System::Numerics::IMultiplicativeIdentity<System::Byte, System::Byte>, System::Numerics::IMultiplyOperators<System::Byte, System::Byte, System::Byte>, System::Numerics::INumber<System::Byte>, System::Numerics::INumberBase<System::Byte>, System::Numerics::IShiftOperators<System::Byte, int, System::Byte>, System::Numerics::ISubtractionOperators<System::Byte, System::Byte, System::Byte>, System::Numerics::IUnaryNegationOperators<System::Byte, System::Byte>, System::Numerics::IUnaryPlusOperators<System::Byte, System::Byte>, System::Numerics::IUnsignedNumber<System::Byte>
public value class System::Byte : IComparable<System::Byte>, IConvertible, IEquatable<System::Byte>, IParsable<System::Byte>, ISpanParsable<System::Byte>, IUtf8SpanFormattable, IUtf8SpanParsable<System::Byte>, System::Numerics::IAdditionOperators<System::Byte, System::Byte, System::Byte>, System::Numerics::IAdditiveIdentity<System::Byte, System::Byte>, System::Numerics::IBinaryInteger<System::Byte>, System::Numerics::IBinaryNumber<System::Byte>, System::Numerics::IBitwiseOperators<System::Byte, System::Byte, System::Byte>, System::Numerics::IComparisonOperators<System::Byte, System::Byte, bool>, System::Numerics::IDecrementOperators<System::Byte>, System::Numerics::IDivisionOperators<System::Byte, System::Byte, System::Byte>, System::Numerics::IEqualityOperators<System::Byte, System::Byte, bool>, System::Numerics::IIncrementOperators<System::Byte>, System::Numerics::IMinMaxValue<System::Byte>, System::Numerics::IModulusOperators<System::Byte, System::Byte, System::Byte>, System::Numerics::IMultiplicativeIdentity<System::Byte, System::Byte>, System::Numerics::IMultiplyOperators<System::Byte, System::Byte, System::Byte>, System::Numerics::INumber<System::Byte>, System::Numerics::INumberBase<System::Byte>, System::Numerics::IShiftOperators<System::Byte, int, System::Byte>, System::Numerics::ISubtractionOperators<System::Byte, System::Byte, System::Byte>, System::Numerics::IUnaryNegationOperators<System::Byte, System::Byte>, System::Numerics::IUnaryPlusOperators<System::Byte, System::Byte>, System::Numerics::IUnsignedNumber<System::Byte>
public value class System::Byte : IComparable, IConvertible, IFormattable
public value class System::Byte : IComparable, IComparable<System::Byte>, IEquatable<System::Byte>, IFormattable
public struct Byte : IComparable, IComparable<byte>, IConvertible, IEquatable<byte>, IFormattable
public readonly struct Byte : IComparable, IComparable<byte>, IConvertible, IEquatable<byte>, IFormattable
public readonly struct Byte : IComparable, IComparable<byte>, IConvertible, IEquatable<byte>, ISpanFormattable
public readonly struct Byte : IComparable<byte>, IConvertible, IEquatable<byte>, IParsable<byte>, ISpanParsable<byte>, System.Numerics.IAdditionOperators<byte,byte,byte>, System.Numerics.IAdditiveIdentity<byte,byte>, System.Numerics.IBinaryInteger<byte>, System.Numerics.IBinaryNumber<byte>, System.Numerics.IBitwiseOperators<byte,byte,byte>, System.Numerics.IComparisonOperators<byte,byte,bool>, System.Numerics.IDecrementOperators<byte>, System.Numerics.IDivisionOperators<byte,byte,byte>, System.Numerics.IEqualityOperators<byte,byte,bool>, System.Numerics.IIncrementOperators<byte>, System.Numerics.IMinMaxValue<byte>, System.Numerics.IModulusOperators<byte,byte,byte>, System.Numerics.IMultiplicativeIdentity<byte,byte>, System.Numerics.IMultiplyOperators<byte,byte,byte>, System.Numerics.INumber<byte>, System.Numerics.INumberBase<byte>, System.Numerics.IShiftOperators<byte,int,byte>, System.Numerics.ISubtractionOperators<byte,byte,byte>, System.Numerics.IUnaryNegationOperators<byte,byte>, System.Numerics.IUnaryPlusOperators<byte,byte>, System.Numerics.IUnsignedNumber<byte>
public readonly struct Byte : IComparable<byte>, IConvertible, IEquatable<byte>, IParsable<byte>, ISpanParsable<byte>, IUtf8SpanFormattable, IUtf8SpanParsable<byte>, System.Numerics.IAdditionOperators<byte,byte,byte>, System.Numerics.IAdditiveIdentity<byte,byte>, System.Numerics.IBinaryInteger<byte>, System.Numerics.IBinaryNumber<byte>, System.Numerics.IBitwiseOperators<byte,byte,byte>, System.Numerics.IComparisonOperators<byte,byte,bool>, System.Numerics.IDecrementOperators<byte>, System.Numerics.IDivisionOperators<byte,byte,byte>, System.Numerics.IEqualityOperators<byte,byte,bool>, System.Numerics.IIncrementOperators<byte>, System.Numerics.IMinMaxValue<byte>, System.Numerics.IModulusOperators<byte,byte,byte>, System.Numerics.IMultiplicativeIdentity<byte,byte>, System.Numerics.IMultiplyOperators<byte,byte,byte>, System.Numerics.INumber<byte>, System.Numerics.INumberBase<byte>, System.Numerics.IShiftOperators<byte,int,byte>, System.Numerics.ISubtractionOperators<byte,byte,byte>, System.Numerics.IUnaryNegationOperators<byte,byte>, System.Numerics.IUnaryPlusOperators<byte,byte>, System.Numerics.IUnsignedNumber<byte>
[System.Serializable]
public struct Byte : IComparable, IConvertible, IFormattable
[System.Serializable]
[System.Runtime.InteropServices.ComVisible(true)]
public struct Byte : IComparable, IComparable<byte>, IConvertible, IEquatable<byte>, IFormattable
public struct Byte : IComparable, IComparable<byte>, IEquatable<byte>, IFormattable
type byte = struct
    interface IConvertible
    interface IFormattable
type byte = struct
    interface IConvertible
    interface ISpanFormattable
    interface IFormattable
type byte = struct
    interface IConvertible
    interface IFormattable
    interface IParsable<byte>
    interface ISpanFormattable
    interface ISpanParsable<byte>
    interface IAdditionOperators<byte, byte, byte>
    interface IAdditiveIdentity<byte, byte>
    interface IBinaryInteger<byte>
    interface IBinaryNumber<byte>
    interface IBitwiseOperators<byte, byte, byte>
    interface IComparisonOperators<byte, byte, bool>
    interface IEqualityOperators<byte, byte, bool>
    interface IDecrementOperators<byte>
    interface IDivisionOperators<byte, byte, byte>
    interface IIncrementOperators<byte>
    interface IModulusOperators<byte, byte, byte>
    interface IMultiplicativeIdentity<byte, byte>
    interface IMultiplyOperators<byte, byte, byte>
    interface INumber<byte>
    interface INumberBase<byte>
    interface ISubtractionOperators<byte, byte, byte>
    interface IUnaryNegationOperators<byte, byte>
    interface IUnaryPlusOperators<byte, byte>
    interface IShiftOperators<byte, int, byte>
    interface IMinMaxValue<byte>
    interface IUnsignedNumber<byte>
type byte = struct
    interface IConvertible
    interface IFormattable
    interface IParsable<byte>
    interface ISpanFormattable
    interface ISpanParsable<byte>
    interface IAdditionOperators<byte, byte, byte>
    interface IAdditiveIdentity<byte, byte>
    interface IBinaryInteger<byte>
    interface IBinaryNumber<byte>
    interface IBitwiseOperators<byte, byte, byte>
    interface IComparisonOperators<byte, byte, bool>
    interface IEqualityOperators<byte, byte, bool>
    interface IDecrementOperators<byte>
    interface IDivisionOperators<byte, byte, byte>
    interface IIncrementOperators<byte>
    interface IModulusOperators<byte, byte, byte>
    interface IMultiplicativeIdentity<byte, byte>
    interface IMultiplyOperators<byte, byte, byte>
    interface INumber<byte>
    interface INumberBase<byte>
    interface ISubtractionOperators<byte, byte, byte>
    interface IUnaryNegationOperators<byte, byte>
    interface IUnaryPlusOperators<byte, byte>
    interface IUtf8SpanParsable<byte>
    interface IShiftOperators<byte, int, byte>
    interface IMinMaxValue<byte>
    interface IUnsignedNumber<byte>
    interface IUtf8SpanFormattable
[<System.Serializable>]
type byte = struct
    interface IFormattable
    interface IConvertible
[<System.Serializable>]
[<System.Runtime.InteropServices.ComVisible(true)>]
type byte = struct
    interface IFormattable
    interface IConvertible
type byte = struct
    interface IFormattable
Public Structure Byte
Implements IComparable, IComparable(Of Byte), IConvertible, IEquatable(Of Byte), IFormattable
Public Structure Byte
Implements IComparable, IComparable(Of Byte), IConvertible, IEquatable(Of Byte), ISpanFormattable
Public Structure Byte
Implements IAdditionOperators(Of Byte, Byte, Byte), IAdditiveIdentity(Of Byte, Byte), IBinaryInteger(Of Byte), IBinaryNumber(Of Byte), IBitwiseOperators(Of Byte, Byte, Byte), IComparable(Of Byte), IComparisonOperators(Of Byte, Byte, Boolean), IConvertible, IDecrementOperators(Of Byte), IDivisionOperators(Of Byte, Byte, Byte), IEqualityOperators(Of Byte, Byte, Boolean), IEquatable(Of Byte), IIncrementOperators(Of Byte), IMinMaxValue(Of Byte), IModulusOperators(Of Byte, Byte, Byte), IMultiplicativeIdentity(Of Byte, Byte), IMultiplyOperators(Of Byte, Byte, Byte), INumber(Of Byte), INumberBase(Of Byte), IParsable(Of Byte), IShiftOperators(Of Byte, Integer, Byte), ISpanParsable(Of Byte), ISubtractionOperators(Of Byte, Byte, Byte), IUnaryNegationOperators(Of Byte, Byte), IUnaryPlusOperators(Of Byte, Byte), IUnsignedNumber(Of Byte)
Public Structure Byte
Implements IAdditionOperators(Of Byte, Byte, Byte), IAdditiveIdentity(Of Byte, Byte), IBinaryInteger(Of Byte), IBinaryNumber(Of Byte), IBitwiseOperators(Of Byte, Byte, Byte), IComparable(Of Byte), IComparisonOperators(Of Byte, Byte, Boolean), IConvertible, IDecrementOperators(Of Byte), IDivisionOperators(Of Byte, Byte, Byte), IEqualityOperators(Of Byte, Byte, Boolean), IEquatable(Of Byte), IIncrementOperators(Of Byte), IMinMaxValue(Of Byte), IModulusOperators(Of Byte, Byte, Byte), IMultiplicativeIdentity(Of Byte, Byte), IMultiplyOperators(Of Byte, Byte, Byte), INumber(Of Byte), INumberBase(Of Byte), IParsable(Of Byte), IShiftOperators(Of Byte, Integer, Byte), ISpanParsable(Of Byte), ISubtractionOperators(Of Byte, Byte, Byte), IUnaryNegationOperators(Of Byte, Byte), IUnaryPlusOperators(Of Byte, Byte), IUnsignedNumber(Of Byte), IUtf8SpanFormattable, IUtf8SpanParsable(Of Byte)
Public Structure Byte
Implements IComparable, IConvertible, IFormattable
Public Structure Byte
Implements IComparable, IComparable(Of Byte), IEquatable(Of Byte), IFormattable
继承
属性
实现
IComparable IComparable<Byte> IConvertible IEquatable<Byte> IFormattable ISpanFormattable IComparable<TSelf> IEquatable<TSelf> IParsable<Byte> IParsable<TSelf> ISpanParsable<Byte> ISpanParsable<TSelf> IAdditionOperators<Byte,Byte,Byte> IAdditionOperators<TSelf,TSelf,TSelf> IAdditiveIdentity<Byte,Byte> IAdditiveIdentity<TSelf,TSelf> IBinaryInteger<Byte> IBinaryNumber<Byte> IBinaryNumber<TSelf> IBitwiseOperators<Byte,Byte,Byte> IBitwiseOperators<TSelf,TSelf,TSelf> IComparisonOperators<Byte,Byte,Boolean> IComparisonOperators<TSelf,TSelf,Boolean> IDecrementOperators<Byte> IDecrementOperators<TSelf> IDivisionOperators<Byte,Byte,Byte> IDivisionOperators<TSelf,TSelf,TSelf> IEqualityOperators<Byte,Byte,Boolean> IEqualityOperators<TSelf,TOther,TResult> IEqualityOperators<TSelf,TSelf,Boolean> IIncrementOperators<Byte> IIncrementOperators<TSelf> IMinMaxValue<Byte> IModulusOperators<Byte,Byte,Byte> IModulusOperators<TSelf,TSelf,TSelf> IMultiplicativeIdentity<Byte,Byte> IMultiplicativeIdentity<TSelf,TSelf> IMultiplyOperators<Byte,Byte,Byte> IMultiplyOperators<TSelf,TSelf,TSelf> INumber<Byte> INumber<TSelf> INumberBase<Byte> INumberBase<TSelf> IShiftOperators<Byte,Int32,Byte> IShiftOperators<TSelf,Int32,TSelf> ISubtractionOperators<Byte,Byte,Byte> ISubtractionOperators<TSelf,TSelf,TSelf> IUnaryNegationOperators<Byte,Byte> IUnaryNegationOperators<TSelf,TSelf> IUnaryPlusOperators<Byte,Byte> IUnaryPlusOperators<TSelf,TSelf> IUnsignedNumber<Byte> IUtf8SpanFormattable IUtf8SpanParsable<Byte> IUtf8SpanParsable<TSelf>

注解

Byte 是一种不可变值类型,它表示值范围为 0 (Byte.MinValue 由常量) 表示到 255 (由常量) 表示 Byte.MaxValue 的无符号整数。 .NET 还包括有符号 8 位整数值类型 , SByte表示范围从 -128 到 127 的值。

实例化字节值

可以通过多种方式实例化 Byte 值:

  • 可以声明变量 Byte ,并为其分配数据类型范围内的 Byte 文本整数值。 以下示例声明两个 Byte 变量,并以此方式为其赋值。

    byte value1 = 64;
    byte value2 = 255;
    
    let value1 = 64uy
    let value2 = 255uy
    
    Dim value1 As Byte = 64
    Dim value2 As Byte = 255
    
  • 可以为字节分配非字节数值。 这是一个收缩转换,因此它需要 C# 和 F# 中的强制转换运算符,或者 Visual Basic 中的转换方法(如果 Option Strict 已启用)。 如果非字节值是 Single包含小数部分的 、 DoubleDecimal 值,则其小数部分的处理取决于执行转换的编译器。 以下示例将多个数值分配给 Byte 变量。

    int int1 = 128;
    try {
       byte value1 = (byte) int1;
       Console.WriteLine(value1);
    }
    catch (OverflowException) {
       Console.WriteLine("{0} is out of range of a byte.", int1);
    }
    
    double dbl2 = 3.997;
    try {
       byte value2 = (byte) dbl2;
       Console.WriteLine(value2);
    }
    catch (OverflowException) {
       Console.WriteLine("{0} is out of range of a byte.", dbl2);
    }
    // The example displays the following output:
    //       128
    //       3
    
    let int1 = 128
    try
        let value1 = byte int1
        printfn $"{value1}"
    with :? OverflowException ->
        printfn $"{int1} is out of range of a byte."
    
    let dbl2 = 3.997
    try
        let value2 = byte dbl2
        printfn $"{value2}"
    with :? OverflowException ->
        printfn $"{dbl2} is out of range of a byte."
    
    // The example displays the following output:
    //       128
    //       3
    
    Dim int1 As Integer = 128
    Try
       Dim value1 As Byte = CByte(int1)
       Console.WriteLine(value1)
    Catch e As OverflowException
       Console.WriteLine("{0} is out of range of a byte.", int1)
    End Try
    
    Dim dbl2 As Double = 3.997
    Try
       Dim value2 As Byte = CByte(dbl2)
       Console.WriteLine(value2)
    Catch e As OverflowException
       Console.WriteLine("{0} is out of range of a byte.", dbl2)
    End Try   
    ' The example displays the following output:
    '       128
    '       4
    
  • 可以调用 类的 Convert 方法,将任何受支持的类型转换为 Byte 值。 这是可能的,IConvertible因为Byte支持 接口。 以下示例演示了如何将值数组 Int32 转换为 Byte 值。

    int[] numbers = { Int32.MinValue, -1, 0, 121, 340, Int32.MaxValue };
    byte result;
    foreach (int number in numbers)
    {
       try {
          result = Convert.ToByte(number);
          Console.WriteLine("Converted the {0} value {1} to the {2} value {3}.",
                            number.GetType().Name, number,
                            result.GetType().Name, result);
       }
       catch (OverflowException) {
          Console.WriteLine("The {0} value {1} is outside the range of the Byte type.",
                            number.GetType().Name, number);
       }
    }
    // The example displays the following output:
    //       The Int32 value -2147483648 is outside the range of the Byte type.
    //       The Int32 value -1 is outside the range of the Byte type.
    //       Converted the Int32 value 0 to the Byte value 0.
    //       Converted the Int32 value 121 to the Byte value 121.
    //       The Int32 value 340 is outside the range of the Byte type.
    //       The Int32 value 2147483647 is outside the range of the Byte type.
    
    open System
    
    let numbers = [| Int32.MinValue; -1; 0; 121; 340; Int32.MaxValue |]
    
    for number in numbers do
        try
            let result = Convert.ToByte number
            printfn $"Converted the {number.GetType().Name} value {number} to the {result.GetType().Name} value {result}."
    
        with :? OverflowException ->
            printfn $"The {number.GetType().Name} value {number} is outside the range of the Byte type."
    
    
    // The example displays the following output:
    //       The Int32 value -2147483648 is outside the range of the Byte type.
    //       The Int32 value -1 is outside the range of the Byte type.
    //       Converted the Int32 value 0 to the Byte value 0.
    //       Converted the Int32 value 121 to the Byte value 121.
    //       The Int32 value 340 is outside the range of the Byte type.
    //       The Int32 value 2147483647 is outside the range of the Byte type.
    
    Dim numbers() As Integer = { Int32.MinValue, -1, 0, 121, 340, Int32.MaxValue }
    Dim result As Byte
    For Each number As Integer In numbers
       Try
          result = Convert.ToByte(number)
          Console.WriteLIne("Converted the {0} value {1} to the {2} value {3}.", _
                            number.GetType().Name, number, _
                            result.GetType().Name, result)
       Catch e As OverflowException
          Console.WriteLine("The {0} value {1} is outside the range of the Byte type.", _
                            number.GetType().Name, number)
       End Try
    Next
    ' The example displays the following output:
    '       The Int32 value -2147483648 is outside the range of the Byte type.
    '       The Int32 value -1 is outside the range of the Byte type.
    '       Converted the Int32 value 0 to the Byte value 0.
    '       Converted the Int32 value 121 to the Byte value 121.
    '       The Int32 value 340 is outside the range of the Byte type.
    '       The Int32 value 2147483647 is outside the range of the Byte type.
    
  • 可以调用 ParseTryParse 方法,将值的字符串表示形式 Byte 转换为 Byte。 字符串可以包含十进制或十六进制数字。 以下示例使用十进制和十六进制字符串演示了分析操作。

    string string1 = "244";
    try {
       byte byte1 = Byte.Parse(string1);
       Console.WriteLine(byte1);
    }
    catch (OverflowException) {
       Console.WriteLine("'{0}' is out of range of a byte.", string1);
    }
    catch (FormatException) {
       Console.WriteLine("'{0}' is out of range of a byte.", string1);
    }
    
    string string2 = "F9";
    try {
       byte byte2 = Byte.Parse(string2,
                               System.Globalization.NumberStyles.HexNumber);
       Console.WriteLine(byte2);
    }
    catch (OverflowException) {
       Console.WriteLine("'{0}' is out of range of a byte.", string2);
    }
    catch (FormatException) {
       Console.WriteLine("'{0}' is out of range of a byte.", string2);
    }
    // The example displays the following output:
    //       244
    //       249
    
    let string1 = "244"
    try
        let byte1 = Byte.Parse string1
        printfn $"{byte1}" 
    with
    | :? OverflowException ->
        printfn $"'{string1}' is out of range of a byte."
    | :? FormatException ->
        printfn $"'{string1}' is out of range of a byte."
    
    let string2 = "F9"
    try
        let byte2 = Byte.Parse(string2, System.Globalization.NumberStyles.HexNumber)
        printfn $"{byte2}"
    with
    | :? OverflowException ->
        printfn $"'{string2}' is out of range of a byte."
    | :? FormatException ->
        printfn $"'{string2}' is out of range of a byte."
    
    // The example displays the following output:
    //       244
    //       249
    
    Dim string1 As String = "244"
    Try
       Dim byte1 As Byte = Byte.Parse(string1)
       Console.WriteLine(byte1)
    Catch e As OverflowException
       Console.WriteLine("'{0}' is out of range of a byte.", string1)
    Catch e As FormatException
       Console.WriteLine("'{0}' is out of range of a byte.", string1)
    End Try
    
    Dim string2 As String = "F9"
    Try
       Dim byte2 As Byte = Byte.Parse(string2,
                                 System.Globalization.NumberStyles.HexNumber)
       Console.WriteLine(byte2)
    Catch e As OverflowException
       Console.WriteLine("'{0}' is out of range of a byte.", string2)
    Catch e As FormatException
       Console.WriteLine("'{0}' is out of range of a byte.", string2)
    End Try
    ' The example displays the following output:
    '       244
    '       249
    

对字节值执行操作

类型 Byte 支持标准数学运算,例如加、减、除、乘、减、求和一元求反。 与其他整型类型一样,Byte该类型还支持按AND位 、、XOROR、左移和右移运算符。

可以使用标准数值运算符来比较两个 Byte 值,也可以调用 CompareToEquals 方法。

还可以调用 类的成员 Math 来执行各种数值运算,包括获取数字的绝对值、计算整数除法中的商和余数、确定两个整数的最大值或最小值、获取数字的符号以及舍入数字。

将字节表示为字符串

类型 Byte 提供对标准和自定义数值格式字符串的完全支持。 (有关详细信息,请参阅 格式设置类型标准数字格式字符串自定义数字格式字符串。) 但是,大多数情况下,字节值表示为一位数到三位数的值,而无需任何其他格式设置,或者表示为两位数的十六进制值。

若要将 Byte 值格式化为没有前导零的整型字符串,可以调用无 ToString() 参数方法。 通过使用“D”格式说明符,还可以在字符串表示形式中包含指定数量的前导零。 通过使用“X”格式说明符,可以将值表示 Byte 为十六进制字符串。 以下示例采用这三种方式设置值数组 Byte 中的元素的格式。

byte[] numbers = { 0, 16, 104, 213 };
foreach (byte number in numbers) {
   // Display value using default formatting.
   Console.Write("{0,-3}  -->   ", number.ToString());
   // Display value with 3 digits and leading zeros.
   Console.Write(number.ToString("D3") + "   ");
   // Display value with hexadecimal.
   Console.Write(number.ToString("X2") + "   ");
   // Display value with four hexadecimal digits.
   Console.WriteLine(number.ToString("X4"));
}
// The example displays the following output:
//       0    -->   000   00   0000
//       16   -->   016   10   0010
//       104  -->   104   68   0068
//       213  -->   213   D5   00D5
let numbers = [| 0; 16; 104; 213 |]
for number in numbers do
    // Display value using default formatting.
    number.ToString()
    |> printf "%-3s  -->   "

    // Display value with 3 digits and leading zeros.
    number.ToString "D3"
    |> printf "%s   "
    
    // Display value with hexadecimal.
    number.ToString "X2"
    |> printf "%s   "
    
    // Display value with four hexadecimal digits.
    number.ToString "X4"
    |> printfn "%s"

// The example displays the following output:
//       0    -->   000   00   0000
//       16   -->   016   10   0010
//       104  -->   104   68   0068
//       213  -->   213   D5   00D5
Dim numbers() As Byte = { 0, 16, 104, 213 }
For Each number As Byte In numbers
   ' Display value using default formatting.
   Console.Write("{0,-3}  -->   ", number.ToString())
   ' Display value with 3 digits and leading zeros.
   Console.Write(number.ToString("D3") + "   ")
   ' Display value with hexadecimal.
   Console.Write(number.ToString("X2") + "   ")
   ' Display value with four hexadecimal digits.
   Console.WriteLine(number.ToString("X4"))
Next   
' The example displays the following output:
'       0    -->   000   00   0000
'       16   -->   016   10   0010
'       104  -->   104   68   0068
'       213  -->   213   D5   00D5

还可以通过调用 ToString(Byte, Int32) 方法并提供 base 作为方法的第二个参数,将值格式化Byte为二进制、八进制、十进制或十六进制字符串。 以下示例调用此方法以显示字节值数组的二进制、八进制和十六进制表示形式。

byte[] numbers ={ 0, 16, 104, 213 };
Console.WriteLine("{0}   {1,8}   {2,5}   {3,5}",
                  "Value", "Binary", "Octal", "Hex");
foreach (byte number in numbers) {
   Console.WriteLine("{0,5}   {1,8}   {2,5}   {3,5}",
                     number, Convert.ToString(number, 2),
                     Convert.ToString(number, 8),
                     Convert.ToString(number, 16));
}
// The example displays the following output:
//       Value     Binary   Octal     Hex
//           0          0       0       0
//          16      10000      20      10
//         104    1101000     150      68
//         213   11010101     325      d5
let numbers = [| 0; 16; 104; 213 |]
printfn "%s   %8s   %5s   %5s" "Value" "Binary" "Octal" "Hex"
for number in numbers do
    printfn $"%5i{number}   %8s{Convert.ToString(number, 2)}   %5s{Convert.ToString(number, 8)}   %5s{Convert.ToString(number, 16)}"
                    
// The example displays the following output:
//       Value     Binary   Octal     Hex
//           0          0       0       0
//          16      10000      20      10
//         104    1101000     150      68
//         213   11010101     325      d5
Dim numbers() As Byte = { 0, 16, 104, 213 }
Console.WriteLine("{0}   {1,8}   {2,5}   {3,5}", _
                  "Value", "Binary", "Octal", "Hex")
For Each number As Byte In numbers
   Console.WriteLine("{0,5}   {1,8}   {2,5}   {3,5}", _
                     number, Convert.ToString(number, 2), _
                     Convert.ToString(number, 8), _
                     Convert.ToString(number, 16))
Next      
' The example displays the following output:
'       Value     Binary   Octal     Hex
'           0          0       0       0
'          16      10000      20      10
'         104    1101000     150      68
'         213   11010101     325      d5

使用非十进制字节值

除了使用单个字节作为十进制值之外,你可能还希望对字节值执行按位运算,或者使用字节数组或字节值的二进制或十六进制表示形式。 例如,方法的 BitConverter.GetBytes 重载可以将每个基元数据类型转换为字节数组,而 BigInteger.ToByteArray 该方法可将 BigInteger 值转换为字节数组。

Byte 值以 8 位表示,仅按其数量级表示,不带符号位。 在对 Byte 值执行按位运算或使用单个位时,请务必记住这一点。 若要对任何两个非小数值执行数值、布尔值或比较运算,这两个值必须使用相同的表示形式。

对两 Byte 个值执行操作时,这些值具有相同的表示形式,因此结果准确。 以下示例对此进行了说明,该示例屏蔽了值的最低位 Byte 以确保其均匀。

using System;
using System.Globalization;

public class Example
{
   public static void Main()
   {
      string[] values = { Convert.ToString(12, 16),
                          Convert.ToString(123, 16),
                          Convert.ToString(245, 16) };

      byte mask = 0xFE;
      foreach (string value in values) {
         Byte byteValue = Byte.Parse(value, NumberStyles.AllowHexSpecifier);
         Console.WriteLine("{0} And {1} = {2}", byteValue, mask,
                           byteValue & mask);
      }
   }
}
// The example displays the following output:
//       12 And 254 = 12
//       123 And 254 = 122
//       245 And 254 = 244
open System
open System.Globalization

let values = 
    [ Convert.ToString(12, 16)
      Convert.ToString(123, 16)
      Convert.ToString(245, 16) ]

let mask = 0xFEuy
for value in values do
    let byteValue = Byte.Parse(value, NumberStyles.AllowHexSpecifier)
    printfn $"{byteValue} And {mask} = {byteValue &&& mask}"
                    

// The example displays the following output:
//       12 And 254 = 12
//       123 And 254 = 122
//       245 And 254 = 244
Imports System.Globalization

Module Example
   Public Sub Main()
      Dim values() As String = { Convert.ToString(12, 16), _
                                 Convert.ToString(123, 16), _
                                 Convert.ToString(245, 16) }
      
      Dim mask As Byte = &hFE
      For Each value As String In values
         Dim byteValue As Byte = Byte.Parse(value, NumberStyles.AllowHexSpecifier)
         Console.WriteLine("{0} And {1} = {2}", byteValue, mask, _ 
                           byteValue And mask)
      Next         
   End Sub
End Module
' The example displays the following output:
'       12 And 254 = 12
'       123 And 254 = 122
'       245 And 254 = 244

另一方面,使用无符号位和有符号位时,由于值对正值使用符号和数量级表示形式,而二者的补补表示形式用于负值,则按位运算会变得复杂 SByte 。 若要执行有意义的按位运算,必须将值转换为两个等效表示形式,并且必须保留有关符号位的信息。 以下示例执行此操作以屏蔽 8 位有符号值和无符号值数组中的位 2 和 4。

using System;
using System.Collections.Generic;
using System.Globalization;

public struct ByteString
{
   public string Value;
   public int Sign;
}

public class Example
{
   public static void Main()
   {
      ByteString[] values = CreateArray(-15, 123, 245);

      byte mask = 0x14;        // Mask all bits but 2 and 4.

      foreach (ByteString strValue in values) {
         byte byteValue = Byte.Parse(strValue.Value, NumberStyles.AllowHexSpecifier);
         Console.WriteLine("{0} ({1}) And {2} ({3}) = {4} ({5})",
                           strValue.Sign * byteValue,
                           Convert.ToString(byteValue, 2),
                           mask, Convert.ToString(mask, 2),
                           (strValue.Sign & Math.Sign(mask)) * (byteValue & mask),
                           Convert.ToString(byteValue & mask, 2));
      }
   }

   private static ByteString[] CreateArray(params int[] values)
   {
      List<ByteString> byteStrings = new List<ByteString>();

      foreach (object value in values) {
         ByteString temp = new ByteString();
         int sign = Math.Sign((int) value);
         temp.Sign = sign;

         // Change two's complement to magnitude-only representation.
         temp.Value = Convert.ToString(((int) value) * sign, 16);

         byteStrings.Add(temp);
      }
      return byteStrings.ToArray();
   }
}
// The example displays the following output:
//       -15 (1111) And 20 (10100) = 4 (100)
//       123 (1111011) And 20 (10100) = 16 (10000)
//       245 (11110101) And 20 (10100) = 20 (10100)
open System
open System.Collections.Generic
open System.Globalization

[<Struct>]
type ByteString =
    { Sign: int
      Value: string }

let createArray values =
    [ for value in values do
        let sign = sign value
        { Sign = sign
         // Change two's complement to magnitude-only representation.
          Value = Convert.ToString(value * sign, 16)} ]


let values = createArray [ -15; 123; 245 ]

let mask = 0x14uy        // Mask all bits but 2 and 4.

for strValue in values do
    let byteValue = Byte.Parse(strValue.Value, NumberStyles.AllowHexSpecifier)
    printfn $"{strValue.Sign * int byteValue} ({Convert.ToString(byteValue, 2)}) And {mask} ({Convert.ToString(mask, 2)}) = {(strValue.Sign &&& (int mask |> sign)) * int (byteValue &&& mask)} ({Convert.ToString(byteValue &&& mask, 2)})"

// The example displays the following output:
//       -15 (1111) And 20 (10100) = 4 (100)
//       123 (1111011) And 20 (10100) = 16 (10000)
//       245 (11110101) And 20 (10100) = 20 (10100)
Imports System.Collections.Generic
Imports System.Globalization

Public Structure ByteString
   Public Value As String
   Public Sign As Integer
End Structure

Module Example
   Public Sub Main()
      Dim values() As ByteString = CreateArray(-15, 123, 245)
      
      Dim mask As Byte = &h14        ' Mask all bits but 2 and 4.
      
      For Each strValue As ByteString In values
         Dim byteValue As Byte = Byte.Parse(strValue.Value, NumberStyles.AllowHexSpecifier)
         Console.WriteLine("{0} ({1}) And {2} ({3}) = {4} ({5})", _ 
                           strValue.Sign * byteValue, _ 
                           Convert.ToString(byteValue, 2), _
                           mask, Convert.ToString(mask, 2), _
                           (strValue.Sign And Math.Sign(mask)) * (byteValue And mask), _
                           Convert.ToString(byteValue And mask, 2))
      Next         
   End Sub
   
   Private Function CreateArray(ParamArray values() As Object) As ByteString()
      Dim byteStrings As New List(Of ByteString)
      For Each value As Object In values
         Dim temp As New ByteString()
         Dim sign As Integer = Math.Sign(value)
         temp.Sign = sign
         ' Change two's complement to magnitude-only representation.
         value = value * sign

         temp.Value = Convert.ToString(value, 16)
         byteStrings.Add(temp)
      Next
      Return byteStrings.ToArray()
   End Function   
End Module
' The example displays the following output:
'       -15 (1111) And 20 (10100) = 4 (100)
'       123 (1111011) And 20 (10100) = 16 (10000)
'       245 (11110101) And 20 (10100) = 20 (10100)

字段

MaxValue

表示 Byte 的最大可能值。 此字段为常数。

MinValue

表示 Byte 的最小可能值。 此字段为常数。

方法

Clamp(Byte, Byte, Byte)

将值固定为非独占最小值和最大值。

CompareTo(Byte)

将此实例与指定的 8 位无符号整数进行比较并返回对其相对值的指示。

CompareTo(Object)

将此实例与指定对象进行比较并返回一个对二者的相对值的指示。

CreateChecked<TOther>(TOther)

从值创建当前类型的实例,为超出当前类型可表示范围的任何值引发溢出异常。

CreateSaturating<TOther>(TOther)

从值创建当前类型的实例,使超出当前类型的可表示范围的任何值饱和。

CreateTruncating<TOther>(TOther)

从值创建当前类型的实例,截断当前类型可表示范围之外的任何值。

DivRem(Byte, Byte)

计算两个值的商和余数。

Equals(Byte)

返回一个值,该值指示此实例和指定的 Byte 对象是否表示相同的值。

Equals(Object)

返回一个值,该值指示此实例是否等于指定的对象。

GetHashCode()

返回此实例的哈希代码。

GetTypeCode()

返回值类型 TypeCodeByte

IsEvenInteger(Byte)

确定值是否表示偶数整数。

IsOddInteger(Byte)

确定值是否表示奇数整数。

IsPow2(Byte)

确定值是否为 2 的幂。

LeadingZeroCount(Byte)

计算值中前导零的数目。

Log2(Byte)

计算值的 log2。

Max(Byte, Byte)

将两个值与更大的计算进行比较。

Min(Byte, Byte)

将两个值与较小的计算进行比较。

Parse(ReadOnlySpan<Byte>, IFormatProvider)

将 UTF-8 字符范围分析为值。

Parse(ReadOnlySpan<Byte>, NumberStyles, IFormatProvider)

将 UTF-8 字符范围分析为值。

Parse(ReadOnlySpan<Char>, IFormatProvider)

将字符范围解析为值。

Parse(ReadOnlySpan<Char>, NumberStyles, IFormatProvider)

将指定样式和区域性特定格式的数字的范围表示形式转换为它的等效 Byte

Parse(String)

将数字的字符串表示形式转换为它的等效 Byte 表示形式。

Parse(String, IFormatProvider)

将指定的区域性特定格式的数字字符串表示形式转换为它的等效 Byte

Parse(String, NumberStyles)

将指定样式的数字的字符串表示形式转换为它的等效 Byte

Parse(String, NumberStyles, IFormatProvider)

将指定样式和区域性特定格式的数字的字符串表示形式转换为它的等效 Byte

PopCount(Byte)

计算值中设置的位数。

RotateLeft(Byte, Int32)

按给定量旋转剩余的值。

RotateRight(Byte, Int32)

按给定量向右旋转值。

Sign(Byte)

计算值的符号。

ToString()

将当前 Byte 对象的值转换为其等效的字符串表示形式。

ToString(IFormatProvider)

使用指定的区域性特定格式设置信息将当前 Byte 对象的值转换为它的等效字符串表示形式。

ToString(String)

使用指定的格式将当前 Byte 对象的值转换为它的等效字符串表示形式。

ToString(String, IFormatProvider)

使用指定的格式和区域性特定格式信息将当前 Byte 对象的值转换为它的等效字符串表示形式。

TrailingZeroCount(Byte)

计算值中尾随零的数目。

TryFormat(Span<Byte>, Int32, ReadOnlySpan<Char>, IFormatProvider)

尝试将当前实例的值格式化为 UTF-8,将其设置为提供的字节范围。

TryFormat(Span<Char>, Int32, ReadOnlySpan<Char>, IFormatProvider)

尝试将当前 8 位无符号整数实例的值的格式设置为提供的字符范围。

TryParse(ReadOnlySpan<Byte>, Byte)

尝试将包含数字字符串表示形式的 UTF-8 字符范围转换为等效的 8 位无符号整数。

TryParse(ReadOnlySpan<Byte>, IFormatProvider, Byte)

尝试将 UTF-8 字符范围解析为值。

TryParse(ReadOnlySpan<Byte>, NumberStyles, IFormatProvider, Byte)

尝试将 UTF-8 字符范围解析为值。

TryParse(ReadOnlySpan<Char>, Byte)

尝试将数字的范围表示形式转换为它的等效 Byte,并返回一个指示转换是否成功的值。

TryParse(ReadOnlySpan<Char>, IFormatProvider, Byte)

尝试将字符范围解析为值。

TryParse(ReadOnlySpan<Char>, NumberStyles, IFormatProvider, Byte)

将指定样式和区域性特定格式的数字的范围表示形式转换为它的等效 Byte。 一个指示转换是否成功的返回值。

TryParse(String, Byte)

尝试将数字的字符串表示形式转换为它的等效 Byte,并返回一个指示转换是否成功的值。

TryParse(String, IFormatProvider, Byte)

尝试将字符串解析为值。

TryParse(String, NumberStyles, IFormatProvider, Byte)

将指定样式和区域性特定格式的数字的字符串表示形式转换为它的等效 Byte。 一个指示转换是否成功的返回值。

显式接口实现

IAdditionOperators<Byte,Byte,Byte>.Addition(Byte, Byte)

将两个值相加以计算其和。

IAdditionOperators<Byte,Byte,Byte>.CheckedAddition(Byte, Byte)

将两个值相加以计算其和。

IAdditiveIdentity<Byte,Byte>.AdditiveIdentity

获取当前类型的累加标识。

IBinaryInteger<Byte>.GetByteCount()

获取将作为 的一部分写入的 TryWriteLittleEndian(Span<Byte>, Int32)字节数。

IBinaryInteger<Byte>.GetShortestBitLength()

获取当前值的最短两个补补表示形式的长度(以位为单位)。

IBinaryInteger<Byte>.TryReadBigEndian(ReadOnlySpan<Byte>, Boolean, Byte)

表示一个 8 位无符号整数。

IBinaryInteger<Byte>.TryReadLittleEndian(ReadOnlySpan<Byte>, Boolean, Byte)

表示一个 8 位无符号整数。

IBinaryInteger<Byte>.TryWriteBigEndian(Span<Byte>, Int32)

尝试以 big-endian 格式将当前值写入给定范围。

IBinaryInteger<Byte>.TryWriteLittleEndian(Span<Byte>, Int32)

尝试以 little-endian 格式将当前值写入给定范围。

IBinaryNumber<Byte>.AllBitsSet

获取二进制类型的实例,其中设置了所有位。

IBitwiseOperators<Byte,Byte,Byte>.BitwiseAnd(Byte, Byte)

计算两个值的按位和 。

IBitwiseOperators<Byte,Byte,Byte>.BitwiseOr(Byte, Byte)

计算两个值的按位或 。

IBitwiseOperators<Byte,Byte,Byte>.ExclusiveOr(Byte, Byte)

计算两个值的独占或两个值。

IBitwiseOperators<Byte,Byte,Byte>.OnesComplement(Byte)

计算给定值的补补表示形式。

IComparable.CompareTo(Object)

将当前实例与同一类型的另一个对象进行比较,并返回一个整数,该整数指示当前实例在排序顺序中的位置是位于另一个对象之前、之后还是与其位置相同。

IComparisonOperators<Byte,Byte,Boolean>.GreaterThan(Byte, Byte)

比较两个值以确定哪个值更大。

IComparisonOperators<Byte,Byte,Boolean>.GreaterThanOrEqual(Byte, Byte)

比较两个值以确定哪个值更大或相等。

IComparisonOperators<Byte,Byte,Boolean>.LessThan(Byte, Byte)

比较两个值以确定哪个值较小。

IComparisonOperators<Byte,Byte,Boolean>.LessThanOrEqual(Byte, Byte)

比较两个值以确定哪个值小于或等于。

IConvertible.GetTypeCode()

返回此实例的 TypeCode

IConvertible.ToBoolean(IFormatProvider)

有关此成员的说明,请参见 ToBoolean(IFormatProvider)

IConvertible.ToByte(IFormatProvider)

有关此成员的说明,请参见 ToByte(IFormatProvider)

IConvertible.ToChar(IFormatProvider)

有关此成员的说明,请参见 ToChar(IFormatProvider)

IConvertible.ToDateTime(IFormatProvider)

不支持此转换。 尝试使用此方法将引发 InvalidCastException

IConvertible.ToDecimal(IFormatProvider)

有关此成员的说明,请参见 ToDecimal(IFormatProvider)

IConvertible.ToDouble(IFormatProvider)

有关此成员的说明,请参见 ToDouble(IFormatProvider)

IConvertible.ToInt16(IFormatProvider)

有关此成员的说明,请参见 ToInt16(IFormatProvider)

IConvertible.ToInt32(IFormatProvider)

有关此成员的说明,请参见 ToInt32(IFormatProvider)

IConvertible.ToInt64(IFormatProvider)

有关此成员的说明,请参见 ToInt64(IFormatProvider)

IConvertible.ToSByte(IFormatProvider)

有关此成员的说明,请参见 ToSByte(IFormatProvider)

IConvertible.ToSingle(IFormatProvider)

有关此成员的说明,请参见 ToSingle(IFormatProvider)

IConvertible.ToType(Type, IFormatProvider)

有关此成员的说明,请参见 ToType(Type, IFormatProvider)

IConvertible.ToUInt16(IFormatProvider)

有关此成员的说明,请参见 ToUInt16(IFormatProvider)

IConvertible.ToUInt32(IFormatProvider)

有关此成员的说明,请参见 ToUInt32(IFormatProvider)

IConvertible.ToUInt64(IFormatProvider)

有关此成员的说明,请参见 ToUInt64(IFormatProvider)

IDecrementOperators<Byte>.CheckedDecrement(Byte)

递减值。

IDecrementOperators<Byte>.Decrement(Byte)

递减值。

IDivisionOperators<Byte,Byte,Byte>.Division(Byte, Byte)

将一个值除以另一个值以计算其商。

IEqualityOperators<Byte,Byte,Boolean>.Equality(Byte, Byte)

比较两个值以确定相等性。

IEqualityOperators<Byte,Byte,Boolean>.Inequality(Byte, Byte)

比较两个值以确定不相等性。

IIncrementOperators<Byte>.CheckedIncrement(Byte)

递增值。

IIncrementOperators<Byte>.Increment(Byte)

递增值。

IMinMaxValue<Byte>.MaxValue

获取当前类型的最大值。

IMinMaxValue<Byte>.MinValue

获取当前类型的最小值。

IModulusOperators<Byte,Byte,Byte>.Modulus(Byte, Byte)

将两个值相除以计算其模数或余数。

IMultiplicativeIdentity<Byte,Byte>.MultiplicativeIdentity

获取当前类型的乘法标识。

IMultiplyOperators<Byte,Byte,Byte>.CheckedMultiply(Byte, Byte)

将两个值相乘以计算其乘积。

IMultiplyOperators<Byte,Byte,Byte>.Multiply(Byte, Byte)

将两个值相乘以计算其乘积。

INumber<Byte>.CopySign(Byte, Byte)

将值的符号复制到另一个值的符号。

INumber<Byte>.MaxNumber(Byte, Byte)

比较两个值以计算较大值,如果输入为 , NaN则返回另一个值。

INumber<Byte>.MinNumber(Byte, Byte)

将两个值进行比较以计算较小的值,如果输入为 NaN,则返回另一个值。

INumberBase<Byte>.Abs(Byte)

计算值的绝对值。

INumberBase<Byte>.IsCanonical(Byte)

确定值是否在其规范表示形式中。

INumberBase<Byte>.IsComplexNumber(Byte)

确定值是否表示复数。

INumberBase<Byte>.IsFinite(Byte)

确定值是否为有限值。

INumberBase<Byte>.IsImaginaryNumber(Byte)

确定值是否表示纯虚数。

INumberBase<Byte>.IsInfinity(Byte)

确定值是否无限。

INumberBase<Byte>.IsInteger(Byte)

确定值是否表示整型数。

INumberBase<Byte>.IsNaN(Byte)

确定值是否为 NaN。

INumberBase<Byte>.IsNegative(Byte)

确定值是否为负值。

INumberBase<Byte>.IsNegativeInfinity(Byte)

确定值是否为负无穷大。

INumberBase<Byte>.IsNormal(Byte)

确定值是否正常。

INumberBase<Byte>.IsPositive(Byte)

确定值是否为正值。

INumberBase<Byte>.IsPositiveInfinity(Byte)

确定值是否为正无穷大。

INumberBase<Byte>.IsRealNumber(Byte)

确定值是否表示实数。

INumberBase<Byte>.IsSubnormal(Byte)

确定值是否为非正常值。

INumberBase<Byte>.IsZero(Byte)

确定值是否为零。

INumberBase<Byte>.MaxMagnitude(Byte, Byte)

将两个值与更大的计算进行比较。

INumberBase<Byte>.MaxMagnitudeNumber(Byte, Byte)

将两个值进行比较,以计算其具有更大的数量级并返回另一个值(如果输入为 NaN)。

INumberBase<Byte>.MinMagnitude(Byte, Byte)

将两个值与较小的计算进行比较。

INumberBase<Byte>.MinMagnitudeNumber(Byte, Byte)

将两个值进行比较,以计算其数量级较小并返回另一个值(如果输入为 NaN)。

INumberBase<Byte>.One

获取类型的值 1

INumberBase<Byte>.Radix

获取类型的基数。

INumberBase<Byte>.TryConvertFromChecked<TOther>(TOther, Byte)

表示一个 8 位无符号整数。

INumberBase<Byte>.TryConvertFromSaturating<TOther>(TOther, Byte)

表示一个 8 位无符号整数。

INumberBase<Byte>.TryConvertFromTruncating<TOther>(TOther, Byte)

表示一个 8 位无符号整数。

INumberBase<Byte>.TryConvertToChecked<TOther>(Byte, TOther)

尝试将当前类型的实例转换为另一种类型,从而引发超出当前类型可表示范围的任何值的溢出异常。

INumberBase<Byte>.TryConvertToSaturating<TOther>(Byte, TOther)

尝试将当前类型的实例转换为另一种类型,使超出当前类型可表示范围的任何值饱和。

INumberBase<Byte>.TryConvertToTruncating<TOther>(Byte, TOther)

尝试将当前类型的实例转换为另一种类型,截断当前类型可表示范围之外的任何值。

INumberBase<Byte>.Zero

获取类型的值 0

IShiftOperators<Byte,Int32,Byte>.LeftShift(Byte, Int32)

将一个值左移一个给定的量。

IShiftOperators<Byte,Int32,Byte>.RightShift(Byte, Int32)

将值向右移动给定的量。

IShiftOperators<Byte,Int32,Byte>.UnsignedRightShift(Byte, Int32)

将值向右移动给定的量。

ISubtractionOperators<Byte,Byte,Byte>.CheckedSubtraction(Byte, Byte)

减去两个值以计算它们的差值。

ISubtractionOperators<Byte,Byte,Byte>.Subtraction(Byte, Byte)

减去两个值以计算它们的差值。

IUnaryNegationOperators<Byte,Byte>.CheckedUnaryNegation(Byte)

计算值的检查一元求反。

IUnaryNegationOperators<Byte,Byte>.UnaryNegation(Byte)

计算值的一元求反。

IUnaryPlusOperators<Byte,Byte>.UnaryPlus(Byte)

计算值的一元加号。

适用于

线程安全性

此类型的所有成员都是线程安全的。 看起来修改实例状态的成员实际上返回使用新值初始化的新实例。 与任何其他类型一样,读取和写入包含此类型的实例的共享变量必须受到锁的保护,以确保线程安全。

另请参阅