共用方式為


編譯器錯誤 CS1935

更新:2007 年 11 月

錯誤訊息

找不到來源型別 'type' 的查詢模式實作。找不到 'method'。您是否遺漏 'System.Core.dll' 的參考或 'System.Linq' 的 using 指示詞?

查詢中的來源型別必須是 IEnumerableIEnumerable<T>、衍生型別 (Derived Type) 或您或其他人已實作標準查詢運算子的型別。如果來源型別是 IEnumerableIEnumerable<T>,則必須加入 system.core.dll 的參考以及 System.Linq 命名空間 (Namespace) 的 using 指示詞,才能將標準查詢運算子擴充方法帶入範圍中使用。標準查詢運算子的自訂實作 (Implementation) 必須以相同的方式帶入範圍 (使用 using 指示詞),而必要時還需要組件 (Assembly) 的參考。

若要更正這個錯誤

  • 將必要的 using 指示詞和參考加入至專案。

範例

因為 System.Linq 的 using 指示詞標記為註解,所以下列程式碼會產生 CS1935:

// cs1935.cs
// CS1935
using System;
using System.Collections.Generic;
// using System.Linq;


class Test
{
    static int Main()
    {
        int[] nums = {0,1,2,3,4,5};
        IEnumerable<int> e = from n in nums
                        where n > 3
                        select n;
        return 0;
    }
}

請參閱

概念

標準查詢運算子概觀