當前位置: 首頁>>代碼示例>>C#>>正文


C# Buffer.SetByte方法代碼示例

本文整理匯總了C#中System.Buffer.SetByte方法的典型用法代碼示例。如果您正苦於以下問題:C# Buffer.SetByte方法的具體用法?C# Buffer.SetByte怎麽用?C# Buffer.SetByte使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在System.Buffer的用法示例。


在下文中一共展示了Buffer.SetByte方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: DisplayArray

// 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" );
    }
}
開發者ID:.NET開發者,項目名稱:System,代碼行數:55,代碼來源:Buffer.SetByte

輸出:

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


注:本文中的System.Buffer.SetByte方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。