简体   繁体   中英

Linq does not work with MonoDevelop/Mono last version on Mac OSX 10.6.4

I'm trying to execute a simple test code:

using System;
using System.IO;
using System.Linq;
using System.Collections.Generic;

namespace TestMono
{
    public class TesterManager
    {
        public TesterManager ()
        {
            Console.WriteLine("Test");
            Path.GetTempPath();

            foreach (var i in new int[] { 1, 2, 3, 4, 5}.Where(n => n % 2 == 0))
        {
            Console.WriteLine(i);
        }

            List<string> ar= new List<string>();
            ar.Add("1"); ar.Add("2");


            var lb = ar.Where(n => n=="2");
        }
    }
}

Compiling that code I have two errors:

Esecuzione compilazione principale...
/Library/Frameworks/Mono.framework/Versions/2.6.4/bin/gmcs /noconfig "/out:/Users/roberto/Projects/TestMono/TestMono/bin/Debug/TestMono.exe" /nologo /warn:4 /debug:+ /debug:full /optimize- /codepage:utf8 /platform:x86 "/define:DEBUG"  /t:exe "/Users/roberto/Projects/TestMono/TestMono/TesterManager.cs" "/Users/roberto/Projects/TestMono/TestMono/Main.cs" 
Compilation failed: 2 error(s), 0 warnings

/Users/roberto/Projects/TestMono/TestMono/TesterManager.cs(15,70): error CS1061: Type `int[]' does not contain a definition for `Where' and no extension method `Where' of type `int[]' could be found (are you missing a using directive or an assembly reference?)
/Users/roberto/Projects/TestMono/TestMono/TesterManager.cs(24,37): error CS1061: Type `System.Collections.Generic.List<string>' does not contain a definition for `Where' and no extension method `Where' of type `System.Collections.Generic.List<string>' could be found (are you missing a using directive or an assembly reference?)

I set the Mono/.NET 3.5 in the project properties and I have the latest version of both Mono and MonoDevelop. I don't understand what is that goes wrong!

You may need to add a reference to "System.Core.dll" in order to access the "System.Linq" namespace.

This one had me scratching my head for a while, I was too used to Resharper bringing in my references.

Did you add a reference to System.Linq.dll (or what ever it is called in Mono)?

(I could swear VS asks the same ;P )

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM