Buffer 클래스
기본 형식의 배열을 조작합니다.
네임스페이스: System
어셈블리: mscorlib(mscorlib.dll)
구문
‘선언
<ComVisibleAttribute(True)> _
Public NotInheritable Class Buffer
‘사용 방법
정적 클래스의 멤버는 클래스 인스턴스를 사용하지 않고 직접 액세스할 수 있습니다.
[ComVisibleAttribute(true)]
public static class Buffer
[ComVisibleAttribute(true)]
public ref class Buffer abstract sealed
/** @attribute ComVisibleAttribute(true) */
public final class Buffer
ComVisibleAttribute(true)
public final class Buffer
설명
Buffer는 기본 형식의 배열에만 영향을 미칩니다. 이 클래스는 개체에 적용되지 않습니다. 기본 형식에 연관된 제한이나 동작에 상관없이 각각의 기본 형식은 일련의 바이트처럼 처리됩니다.
Buffer에는 특정한 기본 형식의 배열에서 다른 기본 형식의 배열로 바이트를 복사하고, 배열에서 바이트를 가져오고, 배열에 바이트를 설정하고, 배열의 길이를 얻기 위한 메서드가 있습니다. 기본 형식을 조작할 때 이 클래스를 사용하면 System.Array 클래스에 있는 비슷한 메서드를 사용할 때보다 성능이 개선됩니다.
Buffer는 Boolean, Char, SByte, Byte, Int16, UInt16, Int32, UInt32, Int64, UInt64, IntPtr, UIntPtr, Single 및 Double 기본 형식에 적용될 수 있습니다.
예제
다음 코드 예제에서는 여러 Buffer 클래스 메서드를 사용하는 방법을 보여 줍니다.
' Example of the Buffer class methods.
Imports System
Imports Microsoft.VisualBasic
Module BufferClassDemo
' Display the array elements from right to left in hexadecimal.
Sub DisplayArray( arr( ) As Short )
Console.Write( " arr:" )
Dim loopX As Integer
For loopX = arr.Length - 1 To 0 Step -1
Console.Write( " {0:X4}", arr( loopX ) )
Next loopX
Console.WriteLine( )
End Sub
Sub Main( )
' This array is to be modified and displayed.
Dim arr( ) As Short = { 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." & vbCrLf & "Note: The " & _
"array is displayed from right to left." & vbCrLf )
Console.WriteLine( "Initial values of array:" & vbCrLf )
' Display the initial array values and ByteLength.
DisplayArray( arr )
Console.WriteLine( vbCrLf & _
"Buffer.ByteLength( arr ): {0}", _
Buffer.ByteLength( arr ) )
' Copy a region of the array; set a byte within the array.
Console.WriteLine( vbCrLf & _
"Call these methods: " & vbCrLf & _
" Buffer.BlockCopy( arr, 5, arr, 16, 9 )," & vbCrLf & _
" Buffer.SetByte( arr, 7, 170 )." & vbCrLf )
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:" & vbCrLf )
DisplayArray( arr )
Console.WriteLine( vbCrLf & _
"Buffer.GetByte( arr, 26 ): {0}", _
Buffer.GetByte( arr, 26 ) )
End Sub
End Module
' 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
// 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
*/
// Example of the Buffer class methods.
using namespace System;
// Display the array elements from right to left in hexadecimal.
void DisplayArray( array<short>^arr )
{
Console::Write( " arr:" );
for ( int loopX = arr->Length - 1; loopX >= 0; loopX-- )
Console::Write( " {0:X4}", arr[ loopX ] );
Console::WriteLine();
}
int main()
{
// This array is to be modified and displayed.
array<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
*/
// Example of the Buffer class methods.
import 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.get_Length() - 1; loopX >= 0; loopX--) {
Console.Write(" {0:X4}", arr.get_Item(loopX));
}
Console.WriteLine();
} //DisplayArray
public static void main(String[] args)
{
// 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}",
(Int32)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, (ubyte)(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}",
System.Convert.ToString(Buffer.GetByte(arr, 26)));
} //main
} //BufferClassDemo
/*
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
*/
상속 계층 구조
System.Object
System.Buffer
스레드로부터의 안전성
이 형식의 모든 public static(Visual Basic의 경우 Shared) 멤버는 스레드로부터 안전합니다. 인터페이스 멤버는 스레드로부터 안전하지 않습니다.
플랫폼
Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
.NET Framework에서 모든 플래폼의 모든 버전을 지원하지는 않습니다. 지원되는 버전의 목록은 시스템 요구 사항을 참조하십시오.
버전 정보
.NET Framework
2.0, 1.1, 1.0에서 지원
.NET Compact Framework
2.0, 1.0에서 지원