Buffer.SetByte メソッドとは? わかりやすく解説

Buffer.SetByte メソッド

指定した配列指定した位置にあるバイトに、指定した値を代入ます。

名前空間: System
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

例外例外
例外種類条件

ArgumentException

arrayプリミティブではありません。

ArgumentNullException

arraynull 参照 (Visual Basic では Nothing) です。

ArgumentOutOfRangeException

index が負か、または array長さ超えてます。

解説解説

array は、プリミティブ配列である必要があります

使用例使用例

SetByte メソッド使用して配列内の特定の位置にあるバイトに値を割り当てるコード例次に示します

' Example of the Buffer.SetByte method.
Imports System
Imports Microsoft.VisualBasic

Module SetByteDemo

    ' Display the array contents in hexadecimal.
    Sub DisplayArray( arr As Array, name As
 String )

        ' Get the array element width; format the formatting string.
        Dim loopX     As Integer
        Dim elemWidth As Integer
 = _
            Buffer.ByteLength( arr ) / arr.Length
        Dim format    As String
 = _
            String.Format( " {{0:X{0}}}",
 2 * elemWidth )

        ' Display the array elements from right to left.
        Console.Write( "{0,7}:", name )
        For loopX = arr.Length - 1 to 0 Step
 -1
            Console.Write( format, arr( loopX ) )
        Next loopX
        Console.WriteLine( )
    End Sub

    Sub Main( )

        ' These are the arrays to be modified with SetByte.
        ' This allocates 10 elements for shorts and 3 elements
        ' for longs in Visual Basic.
        Dim shorts( 9 ) As Short
        Dim longs( 2 )  As Long
  

        Console.WriteLine( "This example of the "
 & _
            "Buffer.SetByte( Array, Integer, Byte ) "
 & vbCrLf & _
            "method generates the following output."
 & vbCrLf & _
            "Note: The arrays are displayed from right to left."
 & _
            vbCrLf )
        Console.WriteLine( "  Initial values of arrays:"
 & vbCrLf )

        ' Display the initial values of the arrays.
        DisplayArray( shorts, "shorts" )
        DisplayArray( longs, "longs" )

        ' Copy two regions of source array to destination array,
        ' and two overlapped copies from source to source.
        Console.WriteLine( vbCrLf & _
            "  Array values after setting byte 3 = 25, "
 & vbCrLf & _
            "  byte 6 = 64, byte 12 = 121, and byte 17 = 196:"
 & vbCrLf )

        Buffer.SetByte( shorts, 3, 25 )
        Buffer.SetByte( shorts, 6, 64 )
        Buffer.SetByte( shorts, 12, 121 )
        Buffer.SetByte( shorts, 17, 196 )
        Buffer.SetByte( longs, 3, 25 )
        Buffer.SetByte( longs, 6, 64 )
        Buffer.SetByte( longs, 12, 121 )
        Buffer.SetByte( longs, 17, 196 )

        ' Display the arrays again.
        DisplayArray( shorts, "shorts" )
        DisplayArray( longs, "longs" )
    End Sub 
End Module 

' This example of the Buffer.SetByte( Array, Integer, Byte )
' method generates the following output.
' Note: The arrays are displayed from right to left.
' 
'   Initial values of arrays:
' 
'  shorts: 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000
'   longs: 0000000000000000 0000000000000000 0000000000000000
' 
'   Array values after setting byte 3 = 25,
'   byte 6 = 64, byte 12 = 121, and byte 17 = 196:
' 
'  shorts: 0000 C400 0000 0079 0000 0000 0040 0000 1900 0000
'   longs: 000000000000C400 0000007900000000 0040000019000000
// Example of the Buffer.SetByte method.
using System;

class SetByteDemo
{
    // Display the array contents in hexadecimal.
    public static void DisplayArray(
 Array arr, string name )
    {
        // Get the array element width; format the formatting string.
        int elemWidth = Buffer.ByteLength( arr ) / arr.Length;
        string format = String.Format( " {{0:X{0}}}",
 2 * elemWidth );

        // Display the array elements from right to left.
        Console.Write( "{0,7}:", name );
        for( int loopX = arr.Length - 1; loopX
 >= 0; loopX-- )
            Console.Write( format, arr.GetValue( loopX ) );
        Console.WriteLine( );
    }

    public static void Main(
 )
    {
        // These are the arrays to be modified with SetByte.
        short[ ] shorts = new short[ 10 ];
        long[ ]  longs  = new long[ 3 ];

        Console.WriteLine( "This example of the " +
            "Buffer.SetByte( Array, int, byte ) \n"
 +
            "method generates the following output.\n" +
            "Note: The arrays are displayed from right to left.\n" );
        Console.WriteLine( "  Initial values of arrays:\n" );

        // Display the initial values of the arrays.
        DisplayArray( shorts, "shorts" );
        DisplayArray( longs, "longs" );

        // Copy two regions of source array to destination array,
        // and two overlapped copies from source to source.
        Console.WriteLine( "\n" +
            "  Array values after setting byte 3 = 25, \n" +
            "  byte 6 = 64, byte 12 = 121, and byte 17 = 196:\n" );

        Buffer.SetByte( shorts, 3, 25 );
        Buffer.SetByte( shorts, 6, 64 );
        Buffer.SetByte( shorts, 12, 121 );
        Buffer.SetByte( shorts, 17, 196 );
        Buffer.SetByte( longs, 3, 25 );
        Buffer.SetByte( longs, 6, 64 );
        Buffer.SetByte( longs, 12, 121 );
        Buffer.SetByte( longs, 17, 196 );

        // Display the arrays again.
        DisplayArray( shorts, "shorts" );
        DisplayArray( longs, "longs" );
    }
}

/*
This example of the Buffer.SetByte( Array, int, byte )
method generates the following output.
Note: The arrays are displayed from right to left.

  Initial values of arrays:

 shorts: 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000
  longs: 0000000000000000 0000000000000000 0000000000000000

  Array values after setting byte 3 = 25,
  byte 6 = 64, byte 12 = 121, and byte 17 = 196:

 shorts: 0000 C400 0000 0079 0000 0000 0040 0000 1900 0000
  longs: 000000000000C400 0000007900000000 0040000019000000
*/
// Example of the Buffer::SetByte method.
using namespace System;

// Display the array contents in hexadecimal.
void DisplayArray( Array^ arr, String^ name )
{
   
   // Get the array element width; format the formatting string.
   int elemWidth = Buffer::ByteLength( arr ) / arr->Length;
   String^ format = String::Format( " {{0:X{0}}}", 2 * elemWidth );
   
   // Display the array elements from right to left.
   Console::Write( "{0,7}:", name );
   for ( int loopX = arr->Length - 1; loopX
 >= 0; loopX-- )
      Console::Write( format, arr->GetValue( loopX ) );
   Console::WriteLine();
}

int main()
{
   
   // These are the arrays to be modified with SetByte.
   array<Int16>^shorts = gcnew array<Int16>(10);
   array<Int64>^longs = gcnew array<Int64>(3);
   Console::WriteLine( "This example of the "
   "Buffer::SetByte( Array*, int, unsigned char
 ) \n"
   "method generates the following output.\n"
   "Note: The arrays are displayed from right to left.\n" );
   Console::WriteLine( "  Initial values of arrays:\n" );
   
   // Display the initial values of the arrays.
   DisplayArray( shorts, "shorts" );
   DisplayArray( longs, "longs" );
   
   // Copy two regions of source array to destination array,
   // and two overlapped copies from source to source.
   Console::WriteLine( "\n  Array values after setting byte 3 = 25, \n"
   "  byte 6 = 64, byte 12 = 121, and byte 17 = 196:\n" );
   Buffer::SetByte( shorts, 3, 25 );
   Buffer::SetByte( shorts, 6, 64 );
   Buffer::SetByte( shorts, 12, 121 );
   Buffer::SetByte( shorts, 17, 196 );
   Buffer::SetByte( longs, 3, 25 );
   Buffer::SetByte( longs, 6, 64 );
   Buffer::SetByte( longs, 12, 121 );
   Buffer::SetByte( longs, 17, 196 );
   
   // Display the arrays again.
   DisplayArray( shorts, "shorts" );
   DisplayArray( longs, "longs" );
}

/*
This example of the Buffer::SetByte( Array*, int, unsigned char
 )
method generates the following output.
Note: The arrays are displayed from right to left.

  Initial values of arrays:

 shorts: 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000
  longs: 0000000000000000 0000000000000000 0000000000000000

  Array values after setting byte 3 = 25,
  byte 6 = 64, byte 12 = 121, and byte 17 = 196:

 shorts: 0000 C400 0000 0079 0000 0000 0040 0000 1900 0000
  longs: 000000000000C400 0000007900000000 0040000019000000
*/
// Example of the Buffer.SetByte method.
import System.*;

class SetByteDemo
{
    // Display the array contents in hexadecimal.
    public static void DisplayArray(Array
 arr, String name)
    {
        // Get the array element width; format the formatting string.
        int elemWidth = Buffer.ByteLength(arr) / arr.get_Length();
        String format = String.Format(" {{0:X{0}}}", (Int32)(2 * elemWidth));

        // Display the array elements from right to left.
        Console.Write("{0,7}:", name);
        for (int loopX = arr.get_Length() -
 1; loopX >= 0; loopX--) {
            Console.Write(format, arr.GetValue(loopX));
        }
        Console.WriteLine();
    } //DisplayArray

    public static void main(String[]
 args)
    {
        // These are the arrays to be modified with SetByte.
        short shorts[] = new short[10];
        long longs[] = new long[3];

        Console.WriteLine(("This example of the "  
            + "Buffer.SetByte( Array, int, byte ) \n"
 
            + "method generates the following output.\n"  
            + "Note: The arrays are displayed from right to left.\n"));
        Console.WriteLine("  Initial values of arrays:\n");

        // Display the initial values of the arrays.
        DisplayArray(shorts, "shorts");
        DisplayArray(longs, "longs");

        // Copy two regions of source array to destination array,
        // and two overlapped copies from source to source.
        Console.WriteLine("\n  Array values after setting byte 3 = 25, \n"
            + "  byte 6 = 64, byte 12 = 121, and byte 17 = 196:\n");
        Buffer.SetByte(shorts, 3, (ubyte)25);
        Buffer.SetByte(shorts, 6, (ubyte)64);
        Buffer.SetByte(shorts, 12, (ubyte)121);
        Buffer.SetByte(shorts, 17, (ubyte)196);
        Buffer.SetByte(longs, 3, (ubyte)25);
        Buffer.SetByte(longs, 6, (ubyte)64);
        Buffer.SetByte(longs, 12, (ubyte)121);
        Buffer.SetByte(longs, 17, (ubyte)196);

        // Display the arrays again.
        DisplayArray(shorts, "shorts");
        DisplayArray(longs, "longs");
    } //main
} //SetByteDemo

/*
This example of the Buffer.SetByte( Array, int, byte )
method generates the following output.
Note: The arrays are displayed from right to left.

  Initial values of arrays:

 shorts: 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000
  longs: 0000000000000000 0000000000000000 0000000000000000

  Array values after setting byte 3 = 25,
  byte 6 = 64, byte 12 = 121, and byte 17 = 196:

 shorts: 0000 C400 0000 0079 0000 0000 0040 0000 1900 0000
  longs: 000000000000C400 0000007900000000 0040000019000000
*/
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照


このページでは「.NET Framework クラス ライブラリ リファレンス」からBuffer.SetByte メソッドを検索した結果を表示しています。
Weblioに収録されているすべての辞書からBuffer.SetByte メソッドを検索する場合は、下記のリンクをクリックしてください。
 全ての辞書からBuffer.SetByte メソッド を検索

英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

「Buffer.SetByte メソッド」の関連用語

Buffer.SetByte メソッドのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



Buffer.SetByte メソッドのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2025 Microsoft.All rights reserved.

©2025 GRAS Group, Inc.RSS