[IronPython] Arrays in IronPython

Alexey Borzenkov snaury at gmail.com
Mon Sep 25 17:29:51 CEST 2006


On 9/23/06, David Anton <dave at tangiblesoftwaresolutions.com> wrote:
> Any idea what the "Array[int][int]" means?
> Iron Python is ok with it, but I can't figure
> out what it is (or how to initialize it).

Looks like second [int] just overrides previous [int]:

  >>> from System import *
  >>> a = Activator.CreateInstance(Array[int], 10)
  >>> a.GetType()
  <System.RuntimeType object at 0x000000000000002B [System.Int32[]]>
  >>> a = Activator.CreateInstance(Array[int][int], 10)
  >>> a.GetType()
  <System.RuntimeType object at 0x000000000000002B [System.Int32[]]>
  >>> a = Activator.CreateInstance(Array[int][int], 10, 10)
  Traceback (most recent call last):
    File , line 0, in <stdin>##20
    File , line 0, in CreateInstance##21
    File mscorlib, line unknown, in CreateInstance
  AttributeError: Constructor on type 'System.Int32[]' not found.
  >>> a = Activator.CreateInstance(Array[int][Byte], 10)
  >>> a.GetType()
  <System.RuntimeType object at 0x000000000000002C [System.Byte[]]>

So it can be initialized the same way as with only one [int]:

  >>> a = Array[int][Byte]((1, 2, 3))
  >>> a.GetType()
  <System.RuntimeType object at 0x000000000000002C [System.Byte[]]>



More information about the Ironpython-users mailing list