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 值。 這是可行的,因為 Byte 支援 IConvertible 介面。 下列範例說明如何將值陣列 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 別也支援位 ANDORXOR 左移和右移運算子。

您可以使用標準數值運算子來比較兩 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) 方法並提供基底做為方法的第二個參數,將值格式化 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.ToByteArrayBigInteger 值轉換成位元組陣列。

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)

判斷值是否為兩個的乘冪。

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)

嘗試將目前值以大端格式寫入指定的範圍。

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

嘗試將目前值以小到尾格式寫入指定的範圍。

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)

計算指定值的 ones-補數標記法。

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)

計算值的一元加號。

適用於

執行緒安全性

此類型的所有成員都是安全線程。 看似修改實例狀態的成員,實際上會傳回以新值初始化的新實例。 如同任何其他類型,讀取和寫入包含此類型實例的共用變數必須受到鎖定保護,以確保執行緒安全。

另請參閱