将Iron Python列表分配给.NET数组
问题描述:
我有一个对.NET数组的元素进行操作的列表理解
I have a list comprehension operating on elements of an .NET array like
obj.arr = [f(x) for x in obj.arr]
但是分配回obj.arr的操作失败.
However the assignment back to obj.arr fails.
是否可以在IronPython中将列表转换为.NET数组?
Is it possible to convert a list to a .NET array in IronPython?
答
尝试一下:
obj.arr = Array[T]([f(x) for x in obj.arr])
用数组元素的类型替换T
.
replacing T
with type of array elements.
或者:
obj.arr = tuple([f(x) for x in obj.arr])