共用方式為


編譯器錯誤 CS1688

更新:2007 年 11 月

錯誤訊息

無法將沒有參數清單的匿名方法區塊轉換為委派型別 'delegate',因為它有一或多個 out 參數

大部分情況下,編譯器允許匿名方法區塊省略參數。當匿名方法區塊沒有參數清單,但委派有 out 參數時,便會發生這個錯誤。編譯器不允許這種情況,因為這樣必須忽略 out 的存在,而這個行為並不正確。

範例

下程式碼會產生錯誤 CS1688。

// CS1688.cs
using System;
delegate void OutParam(out int i);
class ErrorCS1676
{
    static void Main() 
    {
        OutParam o;
        o = delegate  // CS1688
        // Try this instead:
        // o = delegate(out int i)
        { 
            Console.WriteLine("");
        };
    }
}