共用方式為


編譯器錯誤 CS1943

更新:2007 年 11 月

錯誤訊息

在具有來源型別 'type' 的查詢運算式內的後面 from 子句中不允許有型別 'type' 的運算式。'method' 的呼叫時型別推斷失敗。

所有範圍變數必須代表可查詢的型別。

若要更正這個錯誤

  1. 確定型別是實作 IEnumerableIEnumerable<T> 或衍生介面的可查詢型別,或其他已定義查詢模式的任何型別。

  2. 如果型別是非泛型 IEnumerable,請在範圍變數上提供明確型別。

範例

下列程式碼會產生 CS1943:

// cs1943.cs
using System.Linq;
class Test
{
    class TestClass
    { }
    static void Main()
    {
        int[] nums = { 0, 1, 2, 3, 4, 5 };
        TestClass tc = new TestClass();
        
        var x = from n in nums
                from s in tc // CS1943
                select n + s;
    }
}