在python数组和.NET数组之间转换

Mvd*_*vdD 5 .net python arrays ironpython marshalling

我有一个python方法返回一个Python字节array.array('c').

现在,我想使用System.Runtime.InteropServices.Marshal.Copy复制此数组.但是,此方法需要.NET数组.

import array
from System.Runtime.InteropServices import Marshal

bytes = array.array('c')
bytes.append('a')
bytes.append('b')
bytes.append('c')
Marshal.Copy(bytes, dest, 0, 3)
Run Code Online (Sandbox Code Playgroud)

有没有办法在不复制数据的情况下完成这项工作?如果没有,我如何将Python数组中的数据转换为.NET数组?

Gar*_*err 6

要将python数组转换为.NET数组:

import array
from System import Array, Char

x = array.array('c', 'abc')

y = Array[Char](x)
Run Code Online (Sandbox Code Playgroud)

以下是有关在IronPython中创建类型化数组的一些信息:http://www.ironpython.info/index.php? title = Typed_Arrays_in_IronPython