Convert between python array and .NET Array

I have a python method that returns a Python byte array.array ('c').

Now I want to copy this array using System.Runtime.InteropServices.Marshal.Copy. However, this method expects a .NET array.

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) 

Is there any way to make this work without copying the data? If not, how can I convert data into a Python array into a .NET array?

+4
source share
1 answer

To convert a python array to a .NET array:

 import array from System import Array, Char x = array.array('c', 'abc') y = Array[Char](x) 

The following is information about creating typed arrays in IronPython: http://www.ironpython.info/index.php?title=Typed_Arrays_in_IronPython

+6
source

Source: https://habr.com/ru/post/1312523/


All Articles