Byte 結構

定義

表示8位無符號整數。

public value class System::Byte : IComparable, IComparable<System::Byte>, IConvertible, IEquatable<System::Byte>, IFormattable
public value class System::Byte : IComparable<System::Byte>, IConvertible, IEquatable<System::Byte>, IParsable<System::Byte>, ISpanParsable<System::Byte>, 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, 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, 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<byte>, IConvertible, IEquatable<byte>, IParsable<byte>, ISpanParsable<byte>, 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>
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>
[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 IFormattable
    interface IParsable<byte>
    interface ISpanFormattable
    interface ISpanParsable<byte>
    interface IUtf8SpanFormattable
    interface IUtf8SpanParsable<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 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 IUtf8SpanFormattable
    interface IUtf8SpanParsable<byte>
    interface IShiftOperators<byte, int, byte>
    interface IMinMaxValue<byte>
    interface IUnsignedNumber<byte>
[<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 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), IUtf8SpanParsable(Of Byte)
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 IComparable, IConvertible, IFormattable
Public Structure Byte
Implements IComparable, IComparable(Of Byte), IEquatable(Of Byte), IFormattable
繼承
屬性
實作
IComparable IComparable<Byte> IConvertible IEquatable<Byte> IFormattable IComparable<TSelf> IEquatable<TSelf> IParsable<Byte> IParsable<TSelf> ISpanFormattable ISpanParsable<Byte> ISpanParsable<TSelf> IUtf8SpanFormattable IUtf8SpanParsable<Byte> IUtf8SpanParsable<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>

備註

Byte 是不可變的實值類型,代表不帶正負號的整數,其值範圍從 0(以 Byte.MinValue 常數表示)到 255(以 Byte.MaxValue 常數表示)。 .NET 也包含帶正負號的 8 位整數實值類型,SByte,代表範圍從 -128 到 127 的值。

具現化 Byte 值

您可以透過數種方式具現化 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 設為開啟時需要使用轉換方法。 如果非位元組值是包含小數位元件的 SingleDoubleDecimal 值,則其小數部分的處理取決於執行轉換的編譯程式。 下列範例會將數個數值指派給 Byte 變數。

    int int1 = 128;
    try
    {
        byte value1 = (byte)int1;
        Console.WriteLine(value1);
    }
    catch (OverflowException)
    {
        Console.WriteLine($"{int1} is out of range of a byte.");
    }
    
    double dbl2 = 3.997;
    try
    {
        byte value2 = (byte)dbl2;
        Console.WriteLine(value2);
    }
    catch (OverflowException)
    {
        Console.WriteLine($"{dbl2} is out of range of a byte.");
    }
    // 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.
    
    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($"'{string1}' is out of range of a byte.");
    }
    catch (FormatException)
    {
        Console.WriteLine($"'{string1}' is out of range of a byte.");
    }
    
    string string2 = "F9";
    try
    {
        byte byte2 = Byte.Parse(string2,
                                System.Globalization.NumberStyles.HexNumber);
        Console.WriteLine(byte2);
    }
    catch (OverflowException)
    {
        Console.WriteLine($"'{string2}' is out of range of a byte.");
    }
    catch (FormatException)
    {
        Console.WriteLine($"'{string2}' is out of range of a byte.");
    }
    // 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 類型支援標準數學運算,例如加法、減法、除法、乘法、減法、負數和一元負數。 與其他整數類型一樣,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

您也可以呼叫 Byte 方法,並提供基底做為方法的第二個參數,將 ToString(Byte, Int32) 值格式化為二進位、八進位、十六進位或十六進位字串。 下列範例會呼叫這個方法,以顯示位元組值陣列的二進位、八進位和十六進位表示法。

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($"{byteValue} And {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 Example1
    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 BSExample1
{
    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($"{strValue.Sign * byteValue} ({Convert.ToString(byteValue, 2)}) And {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();

        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 Example2
    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)

欄位

名稱 Description
MaxValue

代表 的最大可能值 Byte。 此欄位是常數。

MinValue

代表 的最小值 Byte。 此欄位是常數。

方法

名稱 Description
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()

回傳 TypeCode 的值型別 Byte

IsEvenInteger(Byte)

判斷值是否代表偶數整數。

IsOddInteger(Byte)

判斷值是否代表奇數整數。

IsPow2(Byte)

判斷值是否為兩個乘冪。

LeadingZeroCount(Byte)

計算值中的前置零數目。

Log10(Byte)

表示8位無符號整數。

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, IFormatProvider)

將特定文化格式中的數字字串表示轉換為其 Byte 等價值。

Parse(String, NumberStyles, IFormatProvider)

將特定風格及文化特定格式中的數字字串表示轉換為其 Byte 等價值。

Parse(String, NumberStyles)

將特定風格中的數字字串表示轉換為其 Byte 等價形式。

Parse(String)

將數字的字串表示轉換為其 Byte 等價物。

PopCount(Byte)

計算值中所設定的位數。

RotateLeft(Byte, Int32)

以指定的數量旋轉值。

RotateRight(Byte, Int32)

以指定的數量向右旋轉值。

Sign(Byte)

計算值的符號。

ToString()

將目前 Byte 物件的值轉換為其相等的字串表示。

ToString(IFormatProvider)

利用指定的文化特定格式資訊,將當前 Byte 物件的數值轉換為其等效的字串表示。

ToString(String, IFormatProvider)

利用指定的格式及文化特有的格式資訊,將當前 Byte 物件的值轉換為其等效字串表示。

ToString(String)

將目前 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 等價值。 傳回值表示轉換成功或失敗。

明確介面實作

名稱 Description
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)

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

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-complement 表示法。

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>.MultiplyAddEstimate(Byte, Byte, Byte)

計算估計值為(left * right) + 。 addend

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)

計算值的一元加號。

適用於

執行緒安全性

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

另請參閱