Cliquez pour évaluer et commenter
MSDN
MSDN Library
Développement .NET
.NET Framework 3.5
.NET Framework
Bibliothèque de classes ....
System, espace de noms
Buffer, classe

  Passer à l'affichage pour faible bande passante
Cette page est spécifique à
Microsoft Visual Studio 2008/.NET Framework 3.5

D'autres versions sont également disponibles pour :
Bibliothèque de classes .NET Framework
Buffer, classe

Mise à jour : novembre 2007

Manipule les tableaux de types primitifs.

Espace de noms :  System
Assembly :  mscorlib (dans mscorlib.dll)
Visual Basic (Déclaration)
<ComVisibleAttribute(True)> _
Public NotInheritable Class Buffer
Visual Basic (Utilisation)
Vous n'êtes pas obligé de déclarer une instance d'une classe statique pour accéder à ses membres.
C#
[ComVisibleAttribute(true)]
public static class Buffer
VisualC++
[ComVisibleAttribute(true)]
public ref class Buffer abstract sealed
J#
/** @attribute ComVisibleAttribute(true) */
public final class Buffer
JScript
public final class Buffer

Buffer affecte uniquement les tableaux de types primitifs. Cette classe ne s'applique pas aux objets. Chaque type primitif est considéré comme une série d'octets, indépendamment de tout comportement ou limitation associé au type primitif.

Buffer fournit des méthodes permettant de copier des octets d'un tableau de types primitifs vers un autre, d'obtenir un octet à partir d'un tableau, de définir un octet dans un tableau et d'obtenir la longueur d'un tableau. Lorsqu'il s'agit de la manipulation de types primitifs, cette classe offre de meilleures performances que les méthodes similaires de la classe System..::.Array.

Buffer s'applique aux types primitifs suivants : Boolean, Char, SByte, Byte, Int16, UInt16, Int32, UInt32, Int64, UInt64, IntPtr, UIntPtr, Single et Double.

L'exemple de code suivant illustre l'utilisation de plusieurs méthodes de la classe Buffer.

Visual Basic
' 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

C#
// 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
*/

VisualC++
// 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
*/

J#
// 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
Tous les membres static (Shared en Visual Basic) publics de ce type sont thread-safe. Il n'est pas garanti que les membres d'instance soient thread-safe.

Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professionnel Édition x64, Windows XP Starter Edition, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98, Windows CE, Windows Mobile pour Smartphone, Windows Mobile pour Pocket PC, Xbox 360

Le .NET Framework et le .NET Compact Framework ne prennent pas en charge toutes les versions de chaque plateforme. Pour obtenir la liste des versions prises en charge, consultez Configuration requise du .NET Framework.

.NET Framework

Pris en charge dans : 3.5, 3.0, 2.0, 1.1, 1.0

.NET Compact Framework

Pris en charge dans : 3.5, 2.0, 1.0

XNA Framework

Pris en charge dans : 2.0, 1.0
Contenu de la communauté   Qu'est-ce que le Contenu de la communauté ?
Ajouter du contenu RSS  Annotations
Processing
© 2009 Microsoft Corporation. Tous droits réservés. Conditions d'utilisation  |  Marques  |  Confidentialité
Page view tracker