# RubyArray to List\<T\>?

**URL:** <https://www.ruby-forum.com/t/rubyarray-to-list-t/189554>\
**Category:** IronRuby\
**Created:** [June 3, 2010, 2:28am UTC](https://www.ruby-forum.com/t/rubyarray-to-list-t/189554 "2010-06-03T02:28:54Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![benhiller](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/8e7dd6/32.png) [@benhiller](https://www.ruby-forum.com/u/benhiller)\
**Post date:** [June 3, 2010, 2:28am UTC](https://www.ruby-forum.com/t/rubyarray-to-list-t/189554/1 "2010-06-03T02:28:54Z")

</div>

Hello,

I have a block of code which returns me a RubyArray back into C# code.  
While I can get access to the strongly typed objects inside using  
reflection, I was wondering if there was any way to get the data back  
as a List ?

Example of the code at the moment:  
RubyArray o = (RubyArray)  
filters[1].GetFilteredOutTweets(tweets);  
Console.WriteLine(o);  
Console.WriteLine((o[0] as Tweet).User);

GetFilteredOutTweets returns an object as when it returned List  
it was causing it to fail.

Make sense?

Thanks

Ben

---

<div class="post-metadata">

**Author:** ![benhiller](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/8e7dd6/32.png) [@benhiller](https://www.ruby-forum.com/u/benhiller)\
**Post date:** [June 3, 2010, 2:48am UTC](https://www.ruby-forum.com/t/rubyarray-to-list-t/189554/2 "2010-06-03T02:48:47Z")

</div>

RubyArray is IList, its items might be of arbitrary (different)  
types.

You can certainly try to cast all of them to a single type:  
var list = new List(array.Count);  
foreach (Tweet item in array) {  
list.Add(item);  
}

Tomas

---

<div class="post-metadata">

**Author:** ![benhiller](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/8e7dd6/32.png) [@benhiller](https://www.ruby-forum.com/u/benhiller)\
**Post date:** [June 3, 2010, 10:10pm UTC](https://www.ruby-forum.com/t/rubyarray-to-list-t/189554/3 "2010-06-03T22:10:50Z")

</div>

var list = array.Cast(); would be cleaner.

On Wed, Jun 2, 2010 at 5:47 PM, Tomas M.  
\<[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

> wrote:

> While I can get access to the strongly typed objects inside using  
> GetFilteredOutTweets returns an object as when it returned List it  
> [http://rubyforge.org/mailman/listinfo/ironruby-core](http://rubyforge.org/mailman/listinfo/ironruby-core)
> 
> * * *
> 
> Ironruby-core mailing list  
> [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> [http://rubyforge.org/mailman/listinfo/ironruby-core](http://rubyforge.org/mailman/listinfo/ironruby-core)

–  
“The explanation requiring the fewest assumptions is most likely to be  
correct.”

- Occamâ€™s Razor  
[Occam's razor - Wikipedia](http://en.wikipedia.org/wiki/Occam's_Razor)
