Errore del compilatore CS1943

Aggiornamento: novembre 2007

Messaggio di errore

Un'espressione di tipo 'tipo' non è consentita in una clausola from successiva in un'espressione di query con tipo di origine 'tipo'. Inferenza dei tipi non riuscita nella chiamata a 'metodo'.
An expression of type 'type' is not allowed in a subsequent from clause in a query expression with source type 'type'. Type inference failed in the call to 'method'.

Tutte le variabili di intervallo devono rappresentare tipi queryable.

Per correggere l'errore

  1. Verificare che il tipo sia un tipo queryable che implementa IEnumerable, IEnumerable<T> o un'interfaccia derivata o qualsiasi altro tipo che abbia un modello di query definito appositamente.

  2. Se il tipo è un IEnumerable non generico, fornire un tipo esplicito nella variabile di intervallo.

Esempio

Nel codice seguente viene generato l'errore 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;
    }
}