# Referencing a CLR List in IronRuby

**URL:** <https://www.ruby-forum.com/t/referencing-a-clr-list-in-ironruby/116985>\
**Category:** IronRuby\
**Created:** [October 11, 2007, 9:31pm UTC](https://www.ruby-forum.com/t/referencing-a-clr-list-in-ironruby/116985 "2007-10-11T21:31:55Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![nielsene](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/bc79bd/32.png) [@nielsene](https://www.ruby-forum.com/u/nielsene)\
**Post date:** [October 11, 2007, 9:31pm UTC](https://www.ruby-forum.com/t/referencing-a-clr-list-in-ironruby/116985/1 "2007-10-11T21:31:55Z")

</div>

I can’t figure out how to get items out of any of the CLR List types in  
IronRuby. Here’s a contrived example:

> > > require ‘mscorlib’  
> > > =\> true
> 
> > > foo = System::Collections::ArrayList.new()  
> > > =\> #ArrayList:0x0000056
> 
> > > foo.Item(0)  
> > > System.MissingMethodException: undefined local variable or method `Item’  
> > > for  
> > > #ArrayList:0x0000056:ArrayList

Here’s the only thing I could think of that does work:

> > > foo.ToArray.GetValue(0)  
> > > =\> “Hello”

Does anyone know why that is? Or maybe a better work-around?

Thanks!

-Eric

---

<div class="post-metadata">

**Author:** ![nielsene](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/bc79bd/32.png) [@nielsene](https://www.ruby-forum.com/u/nielsene)\
**Post date:** [October 11, 2007, 9:50pm UTC](https://www.ruby-forum.com/t/referencing-a-clr-list-in-ironruby/116985/2 "2007-10-11T21:50:21Z")

</div>

On 10/11/07, Eric N. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> for #ArrayList:0x0000056:ArrayList  
> The actualy method name will be get\_Item(), I think. But did you try

> > > foo[0]

Might work!

Justin

---

<div class="post-metadata">

**Author:** ![nielsene](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/bc79bd/32.png) [@nielsene](https://www.ruby-forum.com/u/nielsene)\
**Post date:** [October 11, 2007, 9:59pm UTC](https://www.ruby-forum.com/t/referencing-a-clr-list-in-ironruby/116985/3 "2007-10-11T21:59:44Z")

</div>

Good Call. foo.get\_Item() works great. foo[0] throws an exception.

Thanks Justin! That’s much better than ToArray.GetValue…

-Eric

---

<div class="post-metadata">

**Author:** ![nielsene](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/bc79bd/32.png) [@nielsene](https://www.ruby-forum.com/u/nielsene)\
**Post date:** [October 11, 2007, 10:14pm UTC](https://www.ruby-forum.com/t/referencing-a-clr-list-in-ironruby/116985/4 "2007-10-11T22:14:59Z")

</div>

And if anyone is wondering, the set would be:

foo.set\_Item(0, “World”)

Cory

From: removed\_email\_address@domain.invalid  
[[mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)] On Behalf Of Eric N.  
Sent: Thursday, October 11, 2007 4:00 PM  
To: removed\_email\_address@domain.invalid  
Subject: Re: [Ironruby-core] Referencing a CLR List in IronRuby

Good Call. foo.get\_Item() works great. foo[0] throws an exception.

Thanks Justin! That’s much better than ToArray.GetValue…

-Eric  
On 10/11/07, Justin B.  
\<removed\_email\_address@domain.invalid[mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)\> wrote:  
On 10/11/07, Eric N.  
\<removed\_email\_address@domain.invalid[mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)\> wrote:  
I can’t figure out how to get items out of any of the CLR List types in  
IronRuby. Here’s a contrived example:

> > > require ‘mscorlib’  
> > > =\> true  
> > > foo = System::Collections:: ArrayList.new()  
> > > =\> #ArrayList:0x0000056  
> > > foo.Item(0)  
> > > System.MissingMethodException: undefined local variable or method `Item’  
> > > for #ArrayList:0x0000056:ArrayList

The actualy method name will be get\_Item(), I think. But did you try

> > > foo[0]

Might work!

Justin

---

<div class="post-metadata">

**Author:** ![nielsene](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/bc79bd/32.png) [@nielsene](https://www.ruby-forum.com/u/nielsene)\
**Post date:** [October 11, 2007, 10:39pm UTC](https://www.ruby-forum.com/t/referencing-a-clr-list-in-ironruby/116985/5 "2007-10-11T22:39:03Z")

</div>

We’ll have foo[0] working sometime later today. John M. just  
checked in support for injecting each() into IEnumerable things (among  
other nice interop pieces). He just missed out on the IList case.

Thanks,  
-John

From: removed\_email\_address@domain.invalid  
[[mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)] On Behalf Of Cory F.  
Sent: Thursday, October 11, 2007 1:09 PM  
To: removed\_email\_address@domain.invalid  
Subject: Re: [Ironruby-core] Referencing a CLR List in IronRuby

And if anyone is wondering, the set would be:

foo.set\_Item(0, “World”)

Cory

From: removed\_email\_address@domain.invalid  
[[mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)] On Behalf Of Eric N.  
Sent: Thursday, October 11, 2007 4:00 PM  
To: removed\_email\_address@domain.invalid  
Subject: Re: [Ironruby-core] Referencing a CLR List in IronRuby

Good Call. foo.get\_Item() works great. foo[0] throws an exception.

Thanks Justin! That’s much better than ToArray.GetValue…

-Eric  
On 10/11/07, Justin B.  
\<removed\_email\_address@domain.invalid[mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)\> wrote:  
On 10/11/07, Eric N.  
\<removed\_email\_address@domain.invalid[mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)\> wrote:  
I can’t figure out how to get items out of any of the CLR List types in  
IronRuby. Here’s a contrived example:

> > > require ‘mscorlib’  
> > > =\> true  
> > > foo = System::Collections:: ArrayList.new()  
> > > =\> #ArrayList:0x0000056  
> > > foo.Item(0)  
> > > System.MissingMethodException: undefined local variable or method `Item’  
> > > for #ArrayList:0x0000056:ArrayList

The actualy method name will be get\_Item(), I think. But did you try

> > > foo[0]

Might work!

Justin

---

<div class="post-metadata">

**Author:** ![nielsene](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/bc79bd/32.png) [@nielsene](https://www.ruby-forum.com/u/nielsene)\
**Post date:** [October 12, 2007, 12:02am UTC](https://www.ruby-forum.com/t/referencing-a-clr-list-in-ironruby/116985/6 "2007-10-12T00:02:44Z")

</div>

Sweet! Thanks Guys!
