当前位置: 首页>>代码示例>>VB.NET>>正文


VB.NET Buffer.BlockCopy方法代码示例

本文整理汇总了VB.NET中System.Buffer.BlockCopy方法的典型用法代码示例。如果您正苦于以下问题:VB.NET Buffer.BlockCopy方法的具体用法?VB.NET Buffer.BlockCopy怎么用?VB.NET Buffer.BlockCopy使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Buffer的用法示例。


在下文中一共展示了Buffer.BlockCopy方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的VB.NET代码示例。

示例1: Example

Module Example
    ' Display the individual bytes in the array in hexadecimal.
    Sub DisplayArray(arr As Array, name As String)
        Console.Write("{0,11}:", name)
        For ctr As Integer = 0 to arr.Length - 1
            Dim bytes() As Byte = BitConverter.GetBytes(arr(ctr))
            For Each byteValue As Byte In bytes
               Console.Write(" {0:X2}", byteValue)
            Next
        Next
        Console.WriteLine()
    End Sub

    ' Display the individual array element values in hexadecimal.
    Sub DisplayArrayValues(arr As Array, name As String)
       ' Get the length of one element in the array.
       Dim elementLength As Integer = Buffer.ByteLength(arr) / arr.Length
       Dim formatString As String = String.Format(" {{0:X{0}}}", 2 * elementLength)
       Console.Write("{0,11}:", name)
       For ctr As Integer = 0 to arr.Length - 1
         Console.Write(formatString, arr(ctr))
       Next
       Console.WriteLine()  
    End Sub
    
    Sub Main()
       Console.WindowWidth = 120
        ' These are source and destination arrays for BlockCopy.
        Dim src()  As Short = { 258, 259, 260, 261, 262, 263, 264, _
                                 265, 266, 267, 268, 269, 270 }
        Dim dest() As Long = { 17, 18, 19, 20 }

        ' Display the initial value of the arrays in memory.
        Console.WriteLine( "Initial values of arrays:")
        Console.WriteLine("   Array values as Bytes:") 
        DisplayArray(src, "src" )
        DisplayArray(dest, "dest" )
        Console.WriteLine("   Array values:")
        DisplayArrayValues(src, "src")
        DisplayArrayValues(dest, "dest")
        Console.WriteLine()

        ' Copy bytes 5-10 from source to index 7 in destination and display the result.
        Buffer.BlockCopy( src, 5, dest, 7, 6 )
        Console.WriteLine("Buffer.BlockCopy(src, 5, dest, 7, 6 )")
        Console.WriteLine("   Array values as Bytes:")
        DisplayArray(src, "src")
        DisplayArray(dest, "dest")
        Console.WriteLine("   Array values:")
        DisplayArrayValues(src, "src")
        DisplayArrayValues(dest, "dest")
        Console.WriteLine()
        
        ' Copy bytes 16-20 from source to index 22 in destination and display the result. 
        Buffer.BlockCopy( src, 16, dest, 22, 5 )
        Console.WriteLine("Buffer.BlockCopy(src, 16, dest, 22, 5)")
        Console.WriteLine("   Array values as Bytes:")
        DisplayArray(src, "src")
        DisplayArray(dest, "dest")
        Console.WriteLine("   Array values:")
        DisplayArrayValues(src, "src")
        DisplayArrayValues(dest, "dest")
        Console.WriteLine()
         
        ' Copy overlapping range of bytes 4-10 to index 5 in source.
        Buffer.BlockCopy( src, 4, src, 5, 7 )
        Console.WriteLine("Buffer.BlockCopy( src, 4, src, 5, 7)")
        Console.WriteLine("   Array values as Bytes:")
        DisplayArray(src, "src")
        DisplayArray(dest, "dest")
        Console.WriteLine("   Array values:")
        DisplayArrayValues(src, "src")
        DisplayArrayValues(dest, "dest")
        Console.WriteLine()
        
        ' Copy overlapping range of bytes 16-22 to index 15 in source. 
        Buffer.BlockCopy(src, 16, src, 15, 7)
        Console.WriteLine("Buffer.BlockCopy( src, 16, src, 15, 7)")
        Console.WriteLine("   Array values as Bytes:")
        DisplayArray(src, "src")
        DisplayArray(dest, "dest")
        Console.WriteLine("   Array values:")
        DisplayArrayValues(src, "src")
        DisplayArrayValues(dest, "dest")
    End Sub 
End Module
开发者ID:VB.NET开发者,项目名称:System,代码行数:86,代码来源:Buffer.BlockCopy

输出:

Initial values of arrays:
Array values as Bytes:
src: 02 01 03 01 04 01 05 01 06 01 07 01 08 01 09 01 0A 01 0B 01 0C 01 0D 01 0E 01
dest: 11 00 00 00 00 00 00 00 12 00 00 00 00 00 00 00 13 00 00 00 00 00 00 00 14 00 00 00 00 00 00 00
Array values:
src: 0102 0103 0104 0105 0106 0107 0108 0109 010A 010B 010C 010D 010E
dest: 0000000000000011 0000000000000012 0000000000000013 0000000000000014

Buffer.BlockCopy(src, 5, dest, 7, 6 )
Array values as Bytes:
src: 02 01 03 01 04 01 05 01 06 01 07 01 08 01 09 01 0A 01 0B 01 0C 01 0D 01 0E 01
dest: 11 00 00 00 00 00 00 01 05 01 06 01 07 00 00 00 13 00 00 00 00 00 00 00 14 00 00 00 00 00 00 00
Array values:
src: 0102 0103 0104 0105 0106 0107 0108 0109 010A 010B 010C 010D 010E
dest: 0100000000000011 0000000701060105 0000000000000013 0000000000000014

Buffer.BlockCopy(src, 16, dest, 22, 5)
Array values as Bytes:
src: 02 01 03 01 04 01 05 01 06 01 07 01 08 01 09 01 0A 01 0B 01 0C 01 0D 01 0E 01
dest: 11 00 00 00 00 00 00 01 05 01 06 01 07 00 00 00 13 00 00 00 00 00 0A 01 0B 01 0C 00 00 00 00 00
Array values:
src: 0102 0103 0104 0105 0106 0107 0108 0109 010A 010B 010C 010D 010E
dest: 0100000000000011 0000000701060105 010A000000000013 00000000000C010B

Buffer.BlockCopy( src, 4, src, 5, 7)
Array values as Bytes:
src: 02 01 03 01 04 04 01 05 01 06 01 07 08 01 09 01 0A 01 0B 01 0C 01 0D 01 0E 01
dest: 11 00 00 00 00 00 00 01 05 01 06 01 07 00 00 00 13 00 00 00 00 00 0A 01 0B 01 0C 00 00 00 00 00
Array values:
src: 0102 0103 0404 0501 0601 0701 0108 0109 010A 010B 010C 010D 010E
dest: 0100000000000011 0000000701060105 010A000000000013 00000000000C010B

Buffer.BlockCopy( src, 16, src, 15, 7)
Array values as Bytes:
src: 02 01 03 01 04 04 01 05 01 06 01 07 08 01 09 0A 01 0B 01 0C 01 0D 0D 01 0E 01
dest: 11 00 00 00 00 00 00 01 05 01 06 01 07 00 00 00 13 00 00 00 00 00 0A 01 0B 01 0C 00 00 00 00 00
Array values:
src: 0102 0103 0404 0501 0601 0701 0108 0A09 0B01 0C01 0D01 010D 010E
dest: 0100000000000011 0000000701060105 010A000000000013 00000000000C010B

示例2: arr

Const INT_SIZE As Integer = 4
Dim arr() As Integer = { 2, 4, 6, 8, 10, 12, 14, 16, 18, 20 }
Buffer.BlockCopy(arr, 0 * INT_SIZE, arr, 3 * INT_SIZE, 4 * INT_SIZE)
For Each value As Integer In arr
   Console.Write("{0}  ", value)
Next
开发者ID:VB.NET开发者,项目名称:System,代码行数:6,代码来源:Buffer.BlockCopy

输出:

2  4  6  2  4  6  8  16  18  20

示例3: arr

Const INT_SIZE As Integer = 4
Dim arr() As Integer = { 2, 4, 6, 8, 10, 12, 14, 16, 18, 20 }
Buffer.BlockCopy(arr, 3 * INT_SIZE, arr, 0 * INT_SIZE, 4 * INT_SIZE)
For Each value As Integer In arr
   Console.Write("{0}  ", value)
Next
开发者ID:VB.NET开发者,项目名称:System,代码行数:6,代码来源:Buffer.BlockCopy

输出:

8  10  12  14  10  12  14  16  18  20


注:本文中的System.Buffer.BlockCopy方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。