共用方式為


編譯器錯誤 CS1920

更新:2007 年 11 月

錯誤訊息

項目初始設定式不可為空白。

集合初始設定式是由項目初始設定式序列組成。除非項目初始設定式包含指派運算式,否則項目初始設定式不需要用括號括住。然而,如果提供括號,則它們不可以是空白的。如果項目初始設定式是物件初始設定式,則只要初始設定式包含新的物件建立運算式,括號就可以是空白。

若要更正這個錯誤

  • 加入括號之間遺漏的運算式。

  • 如果運算式預定是物件初始設定式,則請在括號前面加入新的物件建立運算式。

範例

下列範例會產生 CS1920:

  // cs1920.cs
using System.Collections.Generic;
public class Test
{
    public static int Main()
    {
        // Error. Empty initializer 
        // for inner list.
        List<List<int>> collection =
            new List<List<int>>() { { } }; // CS1920

        // OK. No initializer for inner list.
        List<List<int>> collection2 =
            new List<List<int>>() {  };

        // OK. Inner list is initialized 
        // to one List<int> with zero elements.
        List<List<int>> collection3 =
            new List<List<int>>() { new List<int> { } };
        return 0;
    }
}

請參閱

參考

物件和集合初始設定式 (C# 程式設計手冊)