How to use LINQ in mono?

I cannot get System.Linq (aka LINQ to Objects) to work. I am running MonoDevelop 2.2.1 on Ubuntu 10 Lucid Lynx with Mono 2.4.4.

They advertise on their website that they implemented LINQ, but I can't even find Enumerable.Range or ToArray() . What's wrong?

+46
linq mono monodevelop
Apr 27 '10 at 2:00
source share
3 answers

I assume that you will need to do:

  • In the settings of your project, set the "Runtime Version" to "Mono / .Net 3.5"
  • Add a link to the System.Core package (right-click links in Solution Explorer)
  • Add "using System.Linq" to your module

after that, your code should compile and execute

hope this helps, believes

+76
Apr 27 '10 at 2:19
source share

Do you gmcs compiler? mcs does not seem to compile code containing Linq.

 $ cat a.cs using System; using System.Linq; class Test { static void Main() { foreach (var i in new int[] { 1, 2, 3, 4, 5}.Where(n => n % 2 == 0)) { Console.WriteLine(i); } } } $ gmcs a.cs $ ./a.exe 2 4 

To compile with gmcs , follow these instructions described in MonoDevelop Frequently Asked Questions :

Is it possible to compile my project using gmcs?

Yes. Right-click on your project, select "Options" → "Runtime" and select "2.0" from the drop-down list.

+4
Apr 27 '10 at 2:05 april
source share

What do you mean when you say "can not find"? Intellisense? Many of the linq methods are extension methods, and monodevelop may not support those used in intellisense. In this case, you can still use them, and your code must compile, it just is not in the drop-down lists.

About extension methods

+1
Apr 27 2018-10-10T00:
source share



All Articles