編譯器錯誤 CS1932
無法指派 'expression' 給範圍變數
編譯器必須能夠推斷範圍變數的類型,而不論其是在 from
子句或 let
子句中所引入。 不可為 Null,因為 null 不是類型,也不可以透過不安全類型的運算式進行指派。
移除無效的指派。
將運算式明確轉換成允許的類型。
下列程式碼會產生 CS1932,因為無法推斷範圍變數的類型。 將值轉換成預期的類型即可修正此錯誤,如下列範例所示。
// CS1932.cs
using System.Linq;
class Test
{
static void Main()
{
var x = from i in Enumerable.Range(1, 100)
let k = null // CS1932
// Try the following line instead.
let k = (string) null
select i;
}
}