Assigning an Iron Python List to a .NET Array

I have a list comprehension working with .NET array elements like

obj.arr = [f(x) for x in obj.arr] 

However, assigning back obj.arr is not performed.

Is it possible to convert a list to a .NET array in IronPython?

+4
source share
2 answers

Try the following:

 obj.arr = Array[T]([f(x) for x in obj.arr]) 

replacing T type of array elements.

As an alternative:

 obj.arr = tuple([f(x) for x in obj.arr]) 
+7
source

Arrays should be printed as far as I know. This works for me:

 num_list = [n for n in range(10)] from System import Array num_arr = Array[int](num_list) 

Similarly for strings and other types.

+4
source

All Articles