Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I use Linq in MonoDevelop 2.0 on OS X?

I installed MonoDevelop 2.0 on my Mac.

I created a new Console Application.

"Hello World" program runs fine.

But I can't use Linq.

using System. doesn't show Linq option.

What should I do?

like image 764
Sam Kong Avatar asked May 15 '09 23:05

Sam Kong


2 Answers

You may need to right-click on your project in the solution view, do Options, Build, General, and set your Target Runtime to Mono / .Net 3.5 or bigger.

Then you can right-click references, do Edit References, and add a reference to System.Core to your project.

like image 69
jpobst Avatar answered Oct 15 '22 21:10

jpobst


I'm running Monodevelop 2.0 and Mono 2.0 on Ubuntu 9.04 and lambda's and Linq work fine.

Contrary to what Thomas Levesque says, System.Core does exist in Mono. Extension methods, lambda's et al are all supported.

You need to use using System.Linq.

public static void Example1()    
{

    List<string> people = new List<string>() 
    { 
        "Granville", "John", "Rachel", "Betty", 
        "Chandler", "Ross", "Monica" 
    };

    IEnumerable<string> query = from p in people where p.Length > 5 
    orderby p select p;

    foreach (string person in query) 
    {
        Console.WriteLine(person);
    }
}
like image 42
Opflash Avatar answered Oct 15 '22 21:10

Opflash