2010-06-11 4 views
4

J'ai une méthode python qui retourne un octet Python array.array ('c').Convertir entre tableau python et .NET Array

Maintenant, je veux copier ce tableau en utilisant System.Runtime.InteropServices.Marshal.Copy. Cette méthode attend cependant un tableau .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) 

Existe-t-il un moyen de faire fonctionner cette fonction sans copier les données? Si non, comment puis-je convertir les données dans le tableau Python au tableau .NET?

Répondre

6

Pour convertir un tableau de python à une matrice .NET:

import array 
from System import Array, Char 

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

y = Array[Char](x) 

Voici quelques informations sur la création de tableaux typés dans IronPython: http://www.ironpython.info/index.php?title=Typed_Arrays_in_IronPython

+0

Merci d'avoir répondu. J'ai déjà trouvé une solution à mon problème de marshaling sur le nouveau groupe IronPython (http://groups.google.com/group/ironpy/t/91a344a5ddb7df39) – MvdD