# Few Small Examples in Linq with IronRuby

**URL:** <https://www.ruby-forum.com/t/few-small-examples-in-linq-with-ironruby/131788>\
**Category:** IronRuby\
**Created:** [March 13, 2008, 8:30am UTC](https://www.ruby-forum.com/t/few-small-examples-in-linq-with-ironruby/131788 "2008-03-13T08:30:04Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![webreservoir](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/e480ec/32.png) [@webreservoir](https://www.ruby-forum.com/u/webreservoir)\
**Post date:** [March 13, 2008, 8:30am UTC](https://www.ruby-forum.com/t/few-small-examples-in-linq-with-ironruby/131788/1 "2008-03-13T08:30:04Z")

</div>

Hello,

I know that its too early to ask or it.

But can someone provide few examples, how Linq with IronRuby will look  
alike.

Since i am reading few books on LINQ in C#, i want to gradually try to  
understand it with IronRuby point of view.

I do not want examples to play around. I want examples to understand  
LINQ with IronRuby.

I hope someone might help me here.

---

<div class="post-metadata">

**Author:** ![webreservoir](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/e480ec/32.png) [@webreservoir](https://www.ruby-forum.com/u/webreservoir)\
**Post date:** [March 13, 2008, 8:53am UTC](https://www.ruby-forum.com/t/few-small-examples-in-linq-with-ironruby/131788/2 "2008-03-13T08:53:43Z")

</div>

I think this should answer your question  
[http://rubyforge.org/pipermail/ironruby-core/2008-January/000706.html](http://rubyforge.org/pipermail/ironruby-core/2008-January/000706.html)

---

<div class="post-metadata">

**Author:** ![webreservoir](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/e480ec/32.png) [@webreservoir](https://www.ruby-forum.com/u/webreservoir)\
**Post date:** [March 13, 2008, 1:46pm UTC](https://www.ruby-forum.com/t/few-small-examples-in-linq-with-ironruby/131788/3 "2008-03-13T13:46:40Z")

</div>

Remove the comma from the URI.

---

<div class="post-metadata">

**Author:** ![webreservoir](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/e480ec/32.png) [@webreservoir](https://www.ruby-forum.com/u/webreservoir)\
**Post date:** [March 13, 2008, 1:40pm UTC](https://www.ruby-forum.com/t/few-small-examples-in-linq-with-ironruby/131788/4 "2008-03-13T13:40:50Z")

</div>

Ivan Porto C. wrote:

> I think this should answer your question  
> [http://rubyforge.org/pipermail/ironruby-core/2008-January/000706.html](http://rubyforge.org/pipermail/ironruby-core/2008-January/000706.html)

* * *

Ho Ivan,

Thanks for pointing me a link. But the link is obsolete now.

* * *

Translating this example:  
[Query Syntax and Method Syntax in LINQ (C#) | Microsoft Learn](http://msdn2.microsoft.com/en-us/library/bb397947.aspx), it will look  
something like this:

require ‘System.Core’  
numbers = [5, 10, 8, 3, 6, 12]  
numbers.where { |num| num % 2 == 0 }.order\_by { |n| n }.each { |i|  
write("#{i} ") }

- John

* * *

I could see the example in Ruby, but the actual msdn2 link is now  
obsolete and the code is removed.

So i am unable to make any comparison.

---

<div class="post-metadata">

**Author:** ![webreservoir](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/e480ec/32.png) [@webreservoir](https://www.ruby-forum.com/u/webreservoir)\
**Post date:** [March 14, 2008, 7:47am UTC](https://www.ruby-forum.com/t/few-small-examples-in-linq-with-ironruby/131788/5 "2008-03-14T07:47:05Z")

</div>

Sorry for my more questions on LINQ.

I just read in LinQ in Action…it goes like this…

In chapter 2, weâ€™ll show you the details of how the programming  
languages  
have been extended to support LINQ. In chapter 3, youâ€™ll learn how to  
write LINQ  
queries. This is where youâ€™ll learn about query operators, query  
expressions, and  
expression trees. But you still have a few things to discover before  
getting there.

what i understand is… C# and [Vb.Net](http://Vb.Net) have been extended to meet the  
LINQ requirement. So now we have C# 3.0 and Vb2008 right.

My question is … what about Ruby 1.8 or 1.9…? are they already  
capable with their inbuilt features to support LINQ or IronRuby shall  
incorporate those extra additions to meet the LINQ requirement…?

How far in IronRby from LINQ now…?

Thanks

---

<div class="post-metadata">

**Author:** ![webreservoir](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/e480ec/32.png) [@webreservoir](https://www.ruby-forum.com/u/webreservoir)\
**Post date:** [March 15, 2008, 7:43am UTC](https://www.ruby-forum.com/t/few-small-examples-in-linq-with-ironruby/131788/6 "2008-03-15T07:43:08Z")

</div>

Web R. wrote:

> But can someone provide few examples, how Linq with IronRuby will look  
> alike.

* * *

I am the second interested.

LINQ 2 SQL is very important. I think few experts should start some  
tutorials about this

Looking at the codes in C# and [Vb.Net](http://Vb.Net) does not make any sense, as we are  
never going that way.

IronRuby + LINQ is the way many like me would go.

---

<div class="post-metadata">

**Author:** ![webreservoir](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/e480ec/32.png) [@webreservoir](https://www.ruby-forum.com/u/webreservoir)\
**Post date:** [March 13, 2008, 2:47pm UTC](https://www.ruby-forum.com/t/few-small-examples-in-linq-with-ironruby/131788/7 "2008-03-13T14:47:27Z")

</div>

John L. (DLR) wrote:

> Remove the comma from the URI.

* * *

Thanks John.

I did not notice that little comma. I just clicked the link.

Here’s the C# Code.

* * *

class QueryVMethodSyntax  
{  
static void Main()  
{  
int[] numbers = { 5, 10, 8, 3, 6, 12};

```
    //Query syntax:
    IEnumerable<int> numQuery1 =
        from num in numbers
        where num % 2 == 0
        orderby num
        select num;

    //Method syntax:
    IEnumerable<int> numQuery2 = numbers.Where(num => num % 2 == 

```

0).OrderBy(n =\> n);

```
    foreach (int i in numQuery1)
    {
        Console.Write(i + " ");
    }
    Console.WriteLine(System.Environment.NewLine);
    foreach (int i in numQuery2)
    {
        Console.Write(i + " ");
    }

    // Keep the console open in debug mode.
    Console.WriteLine(System.Environment.NewLine);
    Console.WriteLine("Press any key to exit");
    Console.ReadKey();
}

```

}  
/\*  
Output:  
6 8 10 12  
6 8 10 12  
\*/

With IronRuby, LINQ would be a fun.

Hope to see such more examples soon.

Thanks

---

<div class="post-metadata">

**Author:** ![webreservoir](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/e480ec/32.png) [@webreservoir](https://www.ruby-forum.com/u/webreservoir)\
**Post date:** [March 27, 2008, 7:18am UTC](https://www.ruby-forum.com/t/few-small-examples-in-linq-with-ironruby/131788/8 "2008-03-27T07:18:51Z")

</div>

Rahil K. wrote:

> Web R. wrote:

> LINQ 2 SQL is very important. I think few experts should start some  
> tutorials about this

I think, its time for some experts to come ahead a start blogging about  
Linq to sql with Iron Ruby to start with.

- 1 on the suggestion by Mr.Rahil

SoftMind
