Byte Struktura

Definicja

Reprezentuje 8-bitową liczbę całkowitą bez znaku.

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
Dziedziczenie
Atrybuty
Implementuje
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>

Uwagi

Byte jest niezmiennym typem wartości, który reprezentuje niepodpisane liczby całkowite z wartościami z zakresu od 0 (reprezentowanym przez stałą Byte.MinValue ) do 255 (która jest reprezentowana przez stałą Byte.MaxValue ). Platforma .NET zawiera również podpisany 8-bitowy typ wartości całkowitej, SBytektóry reprezentuje wartości z zakresu od -128 do 127.

Utworzyć wartość bajtu

Możesz utworzyć wystąpienie Byte wartości na kilka sposobów:

  • Zmienną Byte można zadeklarować i przypisać jej całkowitą wartość literału, należącą do zakresu typu danych Byte. Poniższy przykład deklaruje dwie zmienne Byte i przypisuje im wartości w ten sposób.

    byte value1 = 64;
    byte value2 = 255;
    
    let value1 = 64uy
    let value2 = 255uy
    
    Dim value1 As Byte = 64
    Dim value2 As Byte = 255
    
  • Możesz przypisać wartość liczbową inną niż bajt do bajtu. Jest to konwersja zawężająca, więc wymaga operatora rzutowania w języku C# i F# lub metody konwersji w Visual Basic, jeśli Option Strict jest włączony. Jeśli wartość nie bajtowa jest wartością Single, Doublelub Decimal zawierającą składnik ułamkowy, obsługa jej części ułamkowej zależy od kompilatora wykonującego konwersję. Poniższy przykład przypisuje kilka wartości liczbowych do Byte zmiennych.

    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
    
  • Możesz wywołać metodę Convert klasy, aby przekonwertować dowolny obsługiwany typ na Byte wartość. Jest to możliwe, ponieważ Byte obsługuje interfejs IConvertible. Poniższy przykład ilustruje konwersję tablicy wartości Int32 na wartości 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.
    
  • Możesz wywołać metodę Parse lub TryParse, aby przekonwertować reprezentację ciągu wartości Byte na wartość Byte. Ciąg może zawierać cyfry dziesiętne lub szesnastkowe. Poniższy przykład ilustruje operację analizowania przy użyciu zarówno ciągu dziesiętnego, jak i szesnastkowego.

    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
    

Wykonywanie operacji na wartościach bajtów

Typ Byte obsługuje standardowe operacje matematyczne, takie jak dodawanie, odejmowanie, dzielenie, mnożenie, odejmowanie, negacja i negacja jednoargumentowa. Podobnie jak inne typy całkowite, typ Byte obsługuje również operatory bitowych AND, OR, XOR, przesunięcia w lewo i w prawo.

Można użyć standardowych operatorów liczbowych do porównania dwóch wartości Byte lub wywołać metodę CompareTo lub Equals.

Można również wywołać metody klasy Math, aby wykonać szeroki zakres operacji liczbowych, w tym uzyskanie wartości bezwzględnej liczby, obliczanie ilorazu i reszty z dzielenia całkowitego, określenie maksymalnej lub minimalnej wartości dwóch liczb całkowitych, uzyskanie znaku liczby oraz zaokrąglenie liczby.

Reprezentowanie bajtu jako ciągu

Typ Byte zapewnia pełną obsługę standardowych i niestandardowych ciągów formatu liczbowego. (Aby uzyskać więcej informacji, zobacz Typy formatowania, Standardowe ciągi formatu liczbowego i Niestandardowe ciągi formatu liczbowego). Najczęściej jednak wartości bajtów są reprezentowane jako jednocyfrowe do trzech cyfr bez dodatkowego formatowania lub jako dwucyfrowe wartości szesnastkowe.

Aby sformatować Byte wartość jako ciąg całkowity bez zer wiodących, możesz wywołać metodę bez ToString() parametrów. Używając specyfikatora formatu "D", można również uwzględnić określoną liczbę zer wiodących w reprezentacji ciągu. Za pomocą specyfikatora formatu "X" można reprezentować Byte wartość jako ciąg szesnastkowy. Poniższy przykład formatuje elementy w tablicy Byte wartości na te trzy sposoby.

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

Można również sformatować Byte wartość jako ciąg binarny, ósemkowy, dziesiętny lub szesnastkowy, wywołując ToString(Byte, Int32) metodę i podając bazę jako drugi parametr metody. Poniższy przykład wywołuje tę metodę, aby wyświetlić reprezentacje binarne, ósemkowe i szesnastkowe tablicy wartości bajtowych.

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

Obsługa wartości bajtów niedecymalnych

Oprócz pracy z poszczególnymi bajtami jako wartości dziesiętnych, możesz chcieć wykonać operacje bitowe z wartościami bajtów lub pracować z tablicami bajtów albo z binarnymi lub szesnastkowymi reprezentacjami wartości bajtowych. Na przykład przeciążenia metody BitConverter.GetBytes mogą konwertować każdy z typów danych pierwotnych na tablicę bajtów, a metoda BigInteger.ToByteArray konwertuje wartość BigInteger na tablicę bajtów.

Byte wartości są reprezentowane w 8 bitach bez bitu znaku, jedynie według ich wielkości. Ważne jest, aby mieć to na uwadze podczas wykonywania operacji bitowych na wartościach Byte lub przy pracy z pojedynczymi bitami. Aby wykonać operację liczbową, logiczną lub porównawczą na dwóch wartościach innych niż dziesiętne, obie wartości muszą używać tej samej reprezentacji.

Gdy operacja jest wykonywana na dwóch Byte wartościach, wartości współdzielą tę samą reprezentację, więc wynik jest dokładny. Przedstawiono to w poniższym przykładzie, który maskuje bit najniższej Byte kolejności wartości, aby upewnić się, że jest równomierny.

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

Z drugiej strony, kiedy pracujesz z bitami ze znakiem i bez znaku, operacje bitowe są skomplikowane z powodu tego, że wartości SByte używają reprezentacji znaku i wielkości dla wartości dodatnich oraz reprezentacji uzupełnienia do dwóch dla wartości ujemnych. Aby wykonać znaczącą operację bitową, wartości muszą zostać przekonwertowane na dwie równoważne reprezentacje, a informacje o bitie znaku muszą zostać zachowane. W poniższym przykładzie maskowane są bity 2 i 4 w tablicy 8-bitowych wartości ze znakiem i bez znaku.

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)

Pola

Nazwa Opis
MaxValue

Reprezentuje największą możliwą wartość elementu Byte. To pole jest stałe.

MinValue

Reprezentuje najmniejszą możliwą wartość elementu Byte. To pole jest stałe.

Metody

Nazwa Opis
Clamp(Byte, Byte, Byte)

Zaciska wartość do wartości minimalnej i maksymalnej.

CompareTo(Byte)

Porównuje to wystąpienie z określoną 8-bitową liczbą całkowitą bez znaku i zwraca wskazanie ich wartości względnych.

CompareTo(Object)

Porównuje to wystąpienie z określonym obiektem i zwraca wskazanie ich wartości względnych.

CreateChecked<TOther>(TOther)

Tworzy wystąpienie bieżącego typu na podstawie wartości, zgłaszając wyjątek przepełnienia dla wszystkich wartości, które mieszczą się poza dopuszczalnym zakresem bieżącego typu.

CreateSaturating<TOther>(TOther)

Tworzy wystąpienie bieżącego typu na podstawie wartości, usytując wszystkie wartości, które wykraczają poza reprezentowany zakres bieżącego typu.

CreateTruncating<TOther>(TOther)

Tworzy wystąpienie bieżącego typu na podstawie wartości, obcinając wszystkie wartości, które wykraczają poza reprezentowany zakres bieżącego typu.

DivRem(Byte, Byte)

Oblicza iloraz i pozostałą część dwóch wartości.

Equals(Byte)

Zwraca wartość wskazującą, czy to wystąpienie i określony Byte obiekt reprezentują tę samą wartość.

Equals(Object)

Zwraca wartość wskazującą, czy to wystąpienie jest równe określonemu obiektowi.

GetHashCode()

Zwraca kod skrótu dla tego wystąpienia.

GetTypeCode()

Zwraca wartość TypeCode dla typu Bytewartości .

IsEvenInteger(Byte)

Określa, czy wartość reprezentuje liczbę całkowitą parzystą.

IsOddInteger(Byte)

Określa, czy wartość reprezentuje nieparzystną liczbę całkowitą.

IsPow2(Byte)

Określa, czy wartość jest potęgą dwóch.

LeadingZeroCount(Byte)

Oblicza liczbę zer wiodących w wartości.

Log10(Byte)

Reprezentuje 8-bitową liczbę całkowitą bez znaku.

Log2(Byte)

Oblicza dziennik2 wartości.

Max(Byte, Byte)

Porównuje dwie wartości z obliczeniami, które są większe.

Min(Byte, Byte)

Porównuje dwie wartości z obliczeniami, które są mniejsze.

Parse(ReadOnlySpan<Byte>, IFormatProvider)

Analizuje zakres znaków UTF-8 w wartość.

Parse(ReadOnlySpan<Byte>, NumberStyles, IFormatProvider)

Analizuje zakres znaków UTF-8 w wartość.

Parse(ReadOnlySpan<Char>, IFormatProvider)

Analizuje zakres znaków w wartości.

Parse(ReadOnlySpan<Char>, NumberStyles, IFormatProvider)

Konwertuje reprezentację zakresu liczby w określonym stylu i formacie specyficznym dla kultury na jej Byte odpowiednik.

Parse(String, IFormatProvider)

Konwertuje reprezentację ciągu liczby w określonym formacie specyficznym dla kultury na jego Byte odpowiednik.

Parse(String, NumberStyles, IFormatProvider)

Konwertuje reprezentację ciągu liczby w określonym stylu i formacie specyficznym dla kultury na jego Byte odpowiednik.

Parse(String, NumberStyles)

Konwertuje reprezentację ciągu liczby w określonym stylu na jej Byte odpowiednik.

Parse(String)

Konwertuje reprezentację ciągu liczby na jej Byte odpowiednik.

PopCount(Byte)

Oblicza liczbę bitów ustawionych w wartości.

RotateLeft(Byte, Int32)

Obraca wartość pozostawioną przez daną kwotę.

RotateRight(Byte, Int32)

Obraca wartość w prawo o daną kwotę.

Sign(Byte)

Oblicza znak wartości.

ToString()

Konwertuje wartość bieżącego Byte obiektu na równoważną reprezentację ciągu.

ToString(IFormatProvider)

Konwertuje wartość liczbową bieżącego Byte obiektu na równoważną reprezentację ciągu przy użyciu określonych informacji formatowania specyficznych dla kultury.

ToString(String, IFormatProvider)

Konwertuje wartość bieżącego Byte obiektu na równoważną reprezentację ciągu przy użyciu określonego formatu i informacji o formatowaniu specyficznym dla kultury.

ToString(String)

Konwertuje wartość bieżącego Byte obiektu na równoważną reprezentację ciągu przy użyciu określonego formatu.

TrailingZeroCount(Byte)

Oblicza liczbę końcowych zer w wartości.

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

Próbuje sformatować wartość bieżącego wystąpienia jako UTF-8 w podanym zakresie bajtów.

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

Próbuje sformatować wartość bieżącego 8-bitowego wystąpienia liczby całkowitej bez znaku w podanym zakresie znaków.

TryParse(ReadOnlySpan<Byte>, Byte)

Próbuje przekonwertować zakres znaków UTF-8 zawierający reprezentację ciągu liczby na 8-bitową liczbę całkowitą bez znaku.

TryParse(ReadOnlySpan<Byte>, IFormatProvider, Byte)

Próbuje przeanalizować zakres znaków UTF-8 w wartość.

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

Próbuje przeanalizować zakres znaków UTF-8 w wartość.

TryParse(ReadOnlySpan<Char>, Byte)

Próbuje przekonwertować reprezentację zakresu liczby na jej Byte odpowiednik i zwraca wartość wskazującą, czy konwersja zakończyła się pomyślnie.

TryParse(ReadOnlySpan<Char>, IFormatProvider, Byte)

Próbuje przeanalizować zakres znaków w wartości.

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

Konwertuje reprezentację zakresu liczby w określonym stylu i formacie specyficznym dla kultury na jej Byte odpowiednik. Wartość zwracana wskazuje, czy konwersja zakończyła się powodzeniem, czy niepowodzeniem.

TryParse(String, Byte)

Próbuje przekonwertować reprezentację ciągu liczby na jej Byte odpowiednik i zwraca wartość wskazującą, czy konwersja zakończyła się pomyślnie.

TryParse(String, IFormatProvider, Byte)

Próbuje przeanalizować ciąg w wartości.

TryParse(String, NumberStyles, IFormatProvider, Byte)

Konwertuje reprezentację ciągu liczby w określonym stylu i formacie specyficznym dla kultury na jego Byte odpowiednik. Wartość zwracana wskazuje, czy konwersja zakończyła się powodzeniem, czy niepowodzeniem.

Jawne implementacje interfejsu

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

Dodaje dwie wartości w celu obliczenia ich sumy.

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

Dodaje dwie wartości w celu obliczenia ich sumy.

IAdditiveIdentity<Byte,Byte>.AdditiveIdentity

Pobiera tożsamość addytywnego bieżącego typu.

IBinaryInteger<Byte>.GetByteCount()

Pobiera liczbę bajtów, które zostaną zapisane w ramach elementu TryWriteLittleEndian(Span<Byte>, Int32).

IBinaryInteger<Byte>.GetShortestBitLength()

Pobiera długość w bitach najkrótszej reprezentacji wartości bieżącej.

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

Reprezentuje 8-bitową liczbę całkowitą bez znaku.

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

Reprezentuje 8-bitową liczbę całkowitą bez znaku.

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

Próbuje zapisać bieżącą wartość w formacie big-endian do danego zakresu.

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

Próbuje zapisać bieżącą wartość w formacie little-endian do danego zakresu.

IBinaryNumber<Byte>.AllBitsSet

Pobiera wystąpienie typu binarnego, w którym są ustawione wszystkie bity.

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

Oblicza bitowe wartości i dwie wartości.

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

Oblicza bitowe lub dwie wartości.

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

Oblicza wyłącznie lub dwie wartości.

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

Oblicza reprezentację danej wartości jako uzupełnienie.

IComparable.CompareTo(Object)

Porównuje bieżące wystąpienie z innym obiektem tego samego typu i zwraca liczbę całkowitą wskazującą, czy bieżące wystąpienie poprzedza, następuje, czy występuje w tej samej pozycji w kolejności sortowania co drugi obiekt.

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

Porównuje dwie wartości, aby określić, która wartość jest większa.

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

Porównuje dwie wartości, aby określić, które wartości są większe lub równe.

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

Porównuje dwie wartości, aby określić, które wartości są mniejsze.

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

Porównuje dwie wartości, aby określić, które wartości są mniejsze lub równe.

IConvertible.GetTypeCode()

TypeCode Zwraca wartość dla tego wystąpienia.

IConvertible.ToBoolean(IFormatProvider)

Aby uzyskać opis tego elementu członkowskiego, zobacz ToBoolean(IFormatProvider).

IConvertible.ToByte(IFormatProvider)

Aby uzyskać opis tego elementu członkowskiego, zobacz ToByte(IFormatProvider).

IConvertible.ToChar(IFormatProvider)

Aby uzyskać opis tego elementu członkowskiego, zobacz ToChar(IFormatProvider).

IConvertible.ToDateTime(IFormatProvider)

Ta konwersja nie jest obsługiwana. Próba użycia tej metody zgłasza błąd InvalidCastException.

IConvertible.ToDecimal(IFormatProvider)

Aby uzyskać opis tego elementu członkowskiego, zobacz ToDecimal(IFormatProvider).

IConvertible.ToDouble(IFormatProvider)

Aby uzyskać opis tego elementu członkowskiego, zobacz ToDouble(IFormatProvider).

IConvertible.ToInt16(IFormatProvider)

Aby uzyskać opis tego elementu członkowskiego, zobacz ToInt16(IFormatProvider).

IConvertible.ToInt32(IFormatProvider)

Aby uzyskać opis tego elementu członkowskiego, zobacz ToInt32(IFormatProvider).

IConvertible.ToInt64(IFormatProvider)

Aby uzyskać opis tego elementu członkowskiego, zobacz ToInt64(IFormatProvider).

IConvertible.ToSByte(IFormatProvider)

Aby uzyskać opis tego elementu członkowskiego, zobacz ToSByte(IFormatProvider).

IConvertible.ToSingle(IFormatProvider)

Aby uzyskać opis tego elementu członkowskiego, zobacz ToSingle(IFormatProvider).

IConvertible.ToType(Type, IFormatProvider)

Aby uzyskać opis tego elementu członkowskiego, zobacz ToType(Type, IFormatProvider).

IConvertible.ToUInt16(IFormatProvider)

Aby uzyskać opis tego elementu członkowskiego, zobacz ToUInt16(IFormatProvider).

IConvertible.ToUInt32(IFormatProvider)

Aby uzyskać opis tego elementu członkowskiego, zobacz ToUInt32(IFormatProvider).

IConvertible.ToUInt64(IFormatProvider)

Aby uzyskać opis tego elementu członkowskiego, zobacz ToUInt64(IFormatProvider).

IDecrementOperators<Byte>.CheckedDecrement(Byte)

Dekrementuje wartość.

IDecrementOperators<Byte>.Decrement(Byte)

Dekrementuje wartość.

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

Dzieli jedną wartość przez inną, aby obliczyć ich iloraz.

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

Porównuje dwie wartości w celu określenia równości.

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

Porównuje dwie wartości w celu określenia nierówności.

IIncrementOperators<Byte>.CheckedIncrement(Byte)

Zwiększa wartość.

IIncrementOperators<Byte>.Increment(Byte)

Zwiększa wartość.

IMinMaxValue<Byte>.MaxValue

Pobiera maksymalną wartość bieżącego typu.

IMinMaxValue<Byte>.MinValue

Pobiera minimalną wartość bieżącego typu.

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

Dzieli dwie wartości, aby obliczyć ich modulo lub resztę.

IMultiplicativeIdentity<Byte,Byte>.MultiplicativeIdentity

Pobiera mnożenie tożsamości bieżącego typu.

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

Mnoży dwie wartości, aby obliczyć swój produkt.

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

Mnoży dwie wartości, aby obliczyć swój produkt.

INumber<Byte>.CopySign(Byte, Byte)

Kopiuje znak wartości do znaku innej wartości.

INumber<Byte>.MaxNumber(Byte, Byte)

Porównuje dwie wartości z obliczeniami, które są większe i zwracają drugą wartość, jeśli dane wejściowe to NaN.

INumber<Byte>.MinNumber(Byte, Byte)

Porównuje dwie wartości z obliczeniami, które są mniejsze i zwracają drugą wartość, jeśli dane wejściowe to NaN.

INumberBase<Byte>.Abs(Byte)

Oblicza wartość bezwzględną.

INumberBase<Byte>.IsCanonical(Byte)

Określa, czy wartość znajduje się w jej kanonicznej reprezentacji.

INumberBase<Byte>.IsComplexNumber(Byte)

Określa, czy wartość reprezentuje liczbę zespolonej.

INumberBase<Byte>.IsFinite(Byte)

Określa, czy wartość jest skończona.

INumberBase<Byte>.IsImaginaryNumber(Byte)

Określa, czy wartość reprezentuje czystą liczbę wyimaginowaną.

INumberBase<Byte>.IsInfinity(Byte)

Określa, czy wartość jest nieskończona.

INumberBase<Byte>.IsInteger(Byte)

Określa, czy wartość reprezentuje liczbę całkowitą.

INumberBase<Byte>.IsNaN(Byte)

Określa, czy wartość to NaN.

INumberBase<Byte>.IsNegative(Byte)

Określa, czy wartość jest ujemna.

INumberBase<Byte>.IsNegativeInfinity(Byte)

Określa, czy wartość jest ujemną nieskończonością.

INumberBase<Byte>.IsNormal(Byte)

Określa, czy wartość jest normalna.

INumberBase<Byte>.IsPositive(Byte)

Określa, czy wartość jest dodatnia.

INumberBase<Byte>.IsPositiveInfinity(Byte)

Określa, czy wartość jest dodatnią nieskończonością.

INumberBase<Byte>.IsRealNumber(Byte)

Określa, czy wartość reprezentuje liczbę rzeczywistą.

INumberBase<Byte>.IsSubnormal(Byte)

Określa, czy wartość jest nienormalna.

INumberBase<Byte>.IsZero(Byte)

Określa, czy wartość ma wartość zero.

INumberBase<Byte>.MaxMagnitude(Byte, Byte)

Porównuje dwie wartości z obliczeniami, które są większe.

INumberBase<Byte>.MaxMagnitudeNumber(Byte, Byte)

Porównuje dwie wartości z obliczeniami o większej wielkości i zwraca drugą wartość, jeśli dane wejściowe to NaN.

INumberBase<Byte>.MinMagnitude(Byte, Byte)

Porównuje dwie wartości z obliczeniami, które są mniejsze.

INumberBase<Byte>.MinMagnitudeNumber(Byte, Byte)

Porównuje dwie wartości z obliczeniami o mniejszej wielkości i zwraca drugą wartość, jeśli dane wejściowe to NaN.

INumberBase<Byte>.MultiplyAddEstimate(Byte, Byte, Byte)

Oblicza oszacowanie (left * right) i . addend

INumberBase<Byte>.One

Pobiera wartość 1 typu.

INumberBase<Byte>.Radix

Pobiera podstawę (radix) dla typu.

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

Reprezentuje 8-bitową liczbę całkowitą bez znaku.

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

Reprezentuje 8-bitową liczbę całkowitą bez znaku.

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

Reprezentuje 8-bitową liczbę całkowitą bez znaku.

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

Próbuje przekonwertować wystąpienie bieżącego typu na inny typ, zgłaszając wyjątek przepełnienia dla wszystkich wartości, które mieszczą się poza dopuszczalnym zakresem bieżącego typu.

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

Próbuje przekonwertować wystąpienie bieżącego typu na inny typ, saturując wszystkie wartości, które mieszczą się poza dopuszczalnym zakresem bieżącego typu.

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

Próbuje przekonwertować wystąpienie bieżącego typu na inny typ, obcinając wszystkie wartości, które wykraczają poza reprezentowany zakres bieżącego typu.

INumberBase<Byte>.Zero

Pobiera wartość 0 typu.

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

Przesuwa wartość pozostawioną przez daną kwotę.

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

Przesuwa wartość w prawo o daną kwotę.

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

Przesuwa wartość w prawo o daną kwotę.

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

Odejmuje dwie wartości, aby obliczyć ich różnicę.

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

Odejmuje dwie wartości, aby obliczyć ich różnicę.

IUnaryNegationOperators<Byte,Byte>.CheckedUnaryNegation(Byte)

Oblicza sprawdzoną jednoargumentową negację wartości.

IUnaryNegationOperators<Byte,Byte>.UnaryNegation(Byte)

Oblicza jednoargumentowe negację wartości.

IUnaryPlusOperators<Byte,Byte>.UnaryPlus(Byte)

Oblicza jednoargumentowy plus wartość.

Dotyczy

Bezpieczeństwo wątkowe

Wszyscy członkowie tego typu są bezpieczni wątkami. Elementy członkowskie, które wydają się modyfikować stan wystąpienia, zwracają nowe wystąpienie zainicjowane przy użyciu nowej wartości. Podobnie jak w przypadku dowolnego innego typu odczyt i zapis w zmiennej udostępnionej, która zawiera wystąpienie tego typu, musi być chroniona przez blokadę, aby zagwarantować bezpieczeństwo wątków.

Zobacz też