Byte 構造体

8 ビット符号なし整数を表します。

この型のすべてのメンバの一覧については、Byte メンバ を参照してください。

System.Object
   System.ValueType
      System.Byte

<Serializable>
Public Structure Byte   Implements IComparable, IFormattable, IConvertible
[C#]
[Serializable]
public struct Byte : IComparable, IFormattable, IConvertible
[C++]
[Serializable]
public __value struct Byte : public IComparable, IFormattable,   IConvertible

[JScript] JScript では、.NET Framework の構造体を利用することができます。ただし、独自に定義することはできません。

スレッドセーフ

この型は、マルチスレッド操作に対して安全です。

解説

Byte 値型は、値が 0 から 255 までの範囲の符号なし整数を表します。

Byte は、この型のインスタンスを比較したり、インスタンスの値を文字列形式に変換したり、数値の文字列形式をこの型のインスタンスに変換するためのメソッドを提供します。

書式指定コードで値型の文字列形式を制御する方法については、「 書式設定の概要 」を参照してください。

この型は、 IComparableIFormattable インターフェイス、および IConvertible インターフェイスを実装します。この型の明示的な IConvertible インターフェイス メンバの実装の代わりに、 Convert クラスを使用します。

この型はスレッドセーフであり、複数のスレッドが同時にこの型のインスタンスから読み込むことができます。

使用例

[Visual Basic, C#, C++] バイトの配列を 16 進値で表現した文字列に変換する際の Byte の使用例を次に示します。

 
Class HexTest

   Private Shared hexDigits As Char() =  {"0"c, "1"c, "2"c, "3"c, "4"c, "5"c, "6"c, "7"c, "8"c, "9"c, "A"c, "B"c, "C"c, "D"c, "E"c, "F"c}
   
   Public Shared Function ToHexString(bytes() As Byte) As String

      Dim hexStr As String = ""
      Dim i As Integer
      For i = 0 To bytes.Length - 1
     hexStr = hexStr + Hex(bytes(i))
      Next i
      Return hexStr 

   End Function 'ToHexString

  
   Shared Sub Main()
      
      Dim b As Byte() =  {&H0, &H12, &H34, &H56, &HAA, &H55, &HFF}
      Console.WriteLine(ToHexString(b))

   End Sub 'Main

End Class 'HexTest


[C#] 
class HexTest
{
    static char[] hexDigits = {
        '0', '1', '2', '3', '4', '5', '6', '7',
        '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};
 
    public static string ToHexString(byte[] bytes) {
        char[] chars = new char[bytes.Length * 2];
        for (int i = 0; i < bytes.Length; i++) {
            int b = bytes[i];
            chars[i * 2] = hexDigits[b >> 4];
            chars[i * 2 + 1] = hexDigits[b & 0xF];
        }
        return new string(chars);
    }
 
    static void Main() {

        byte[] b = {0x00, 0x12, 0x34, 0x56, 0xAA, 0x55, 0xFF};
        Console.WriteLine(ToHexString(b));
    }
}


[C++] 
__gc class HexTest
{
   static Char hexDigits[] = {
      '0', '1', '2', '3', '4', '5', '6', '7',
      '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};

public:
   static String* ToHexString(Byte bytes[]) {
      Char chars[] = new Char[bytes->Length * 2];
      for (int i = 0; i < bytes->Length; i++) {
         int b = bytes[i];
         chars[i * 2] = hexDigits[b >> 4];
         chars[i * 2 + 1] = hexDigits[b & 0xF];
      }
      return new String(chars);
   }
};

int main() {

   Byte b[] = {0x00, 0x12, 0x34, 0x56, 0xAA, 0x55, 0xFF};
   Console::WriteLine(HexTest::ToHexString(b));
}

[JScript] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン 言語のフィルタ をクリックします。

必要条件

名前空間: System

プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ, .NET Compact Framework - Windows CE .NET

アセンブリ: Mscorlib (Mscorlib.dll 内)

参照

Byte メンバ | System 名前空間 | SByte | String | IComparable | IFormattable | IConvertible