英語で読む

次の方法で共有


Buffer クラス

定義

プリミティブ型の配列を操作します。

public static class Buffer
public sealed class Buffer
[System.Runtime.InteropServices.ComVisible(true)]
public static class Buffer
継承
Buffer
属性

次のコード例は、いくつかの Buffer クラス メソッドの使用を示しています。

// Example of the Buffer class methods.
using System;

class BufferClassDemo
{
    // Display the array elements from right to left in hexadecimal.
    public static void DisplayArray( short[ ] arr )
    {
        Console.Write( "  arr:" );
        for( int loopX = arr.Length - 1; loopX >= 0; loopX-- )
            Console.Write( " {0:X4}", arr[ loopX ] );
        Console.WriteLine( );
    }

    public static void Main( )
    {
        // This array is to be modified and displayed.
        short[ ] arr = { 258, 259, 260, 261, 262, 263, 264,
                         265, 266, 267, 268, 269, 270, 271 };

        Console.WriteLine( "This example of the Buffer class " +
            "methods generates the following output.\n" +
            "Note: The array is displayed from right to left.\n" );
        Console.WriteLine( "Initial values of array:\n" );

        // Display the initial array values and ByteLength.
        DisplayArray( arr );
        Console.WriteLine( "\nBuffer.ByteLength( arr ): {0}",
            Buffer.ByteLength( arr ) );

        // Copy a region of the array; set a byte within the array.
        Console.WriteLine( "\nCall these methods: \n" +
            "  Buffer.BlockCopy( arr, 5, arr, 16, 9 ),\n" +
            "  Buffer.SetByte( arr, 7, 170 ).\n" );

        Buffer.BlockCopy( arr, 5, arr, 16, 9 );
        Buffer.SetByte( arr, 7, 170 );

        // Display the array and a byte within the array.
        Console.WriteLine( "Final values of array:\n" );
        DisplayArray( arr );
        Console.WriteLine( "\nBuffer.GetByte( arr, 26 ): {0}",
            Buffer.GetByte( arr, 26 ) );
    }
}

/*
This example of the Buffer class methods generates the following output.
Note: The array is displayed from right to left.

Initial values of array:

  arr: 010F 010E 010D 010C 010B 010A 0109 0108 0107 0106 0105 0104 0103 0102

Buffer.ByteLength( arr ): 28

Call these methods:
  Buffer.BlockCopy( arr, 5, arr, 16, 9 ),
  Buffer.SetByte( arr, 7, 170 ).

Final values of array:

  arr: 010F 0101 0801 0701 0601 0501 0109 0108 0107 0106 AA05 0104 0103 0102

Buffer.GetByte( arr, 26 ): 15
*/

注釈

Buffer はプリミティブ型の配列にのみ影響します。このクラスはオブジェクトには適用されません。 各プリミティブ型は、プリミティブ型に関連付けられている動作や制限に関係なく、一連のバイトとして扱われます。

Buffer には、プリミティブ型の配列からプリミティブ型の別の配列にバイトをコピーし、配列からバイトを取得し、配列にバイトを設定し、配列の長さを取得するメソッドが用意されています。 このクラスは、 クラス内の同様のメソッドよりもプリミティブ型を操作するためのパフォーマンスが System.Array 向上します。

Bufferは、、および のプリミティブ型BooleanSByteUInt16Int32Int16UInt32Int64ByteCharIntPtrUIntPtrUInt64Singleに適用できます。Double

メソッド

BlockCopy(Array, Int32, Array, Int32, Int32)

コピー先の配列の指定したオフセット位置を先頭として、コピー元の配列の指定したオフセットから指定数のバイトをコピーします。

ByteLength(Array)

指定した配列のバイト数を返します。

GetByte(Array, Int32)

指定した配列の指定した位置にあるバイトを取得します。

MemoryCopy(Void*, Void*, Int64, Int64)

長整数値として指定されたバイト数を、メモリ内のアドレス間でコピーします。

この API は、CLS に準拠していません。

MemoryCopy(Void*, Void*, UInt64, UInt64)

符号なし長整数値として指定されたバイト数を、メモリ内のアドレス間でコピーします。

この API は、CLS に準拠していません。

SetByte(Array, Int32, Byte)

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

適用対象

製品 バージョン
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 2.0, 2.1
UWP 10.0