本文整理汇总了C#中System.Buffer类的典型用法代码示例。如果您正苦于以下问题:C# Buffer类的具体用法?C# Buffer怎么用?C# Buffer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Buffer类属于System命名空间,在下文中一共展示了Buffer类的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: DisplayArray
// 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 ) );
}
}
开发者ID:.NET开发者,项目名称:System,代码行数:45,代码来源:Buffer 输出:
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.Buffer类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论