[英]Linq does not work with MonoDevelop/Mono last version on Mac OSX 10.6.4
我正在嘗試執行一個簡單的測試代碼:
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");
}
}
}
編譯該代碼我有兩個錯誤:
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?)
我在項目屬性中設置了Mono / .NET 3.5,並且具有Mono和MonoDevelop的最新版本。 我不明白這是怎么回事!
您可能需要添加對“ System.Core.dll”的引用才能訪問“ System.Linq”命名空間。
這個讓我撓了一下頭,我已經習慣於Resharper引入我的參考文獻。
您是否添加了對System.Linq.dll的引用(或在Mono中稱為的引用)?
(我可以發誓VS問同樣的問題; P)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.