共用方式為


編譯器錯誤 CS1925

更新:2007 年 11 月

錯誤訊息

無法使用集合初始設定式來初始化型別 'type' 的物件。

只有符合特定準則的集合類別 (Class),才允許集合初始設定式。如需詳細資訊,請參閱物件和集合初始設定式 (C# 程式設計手冊)。嘗試在集合初始設定式內使用簡短格式的巢狀陣列初始設定式時,也會產生這個錯誤。

若要更正這個錯誤

  • 呼叫物件的建構函式 (Constructor) 和方法,來初始化物件。

範例

下列程式碼會產生 CS1925:

// cs1925.cs
public class Student
{
    public int[] Scores;
}

class Test
{
    static void Main(string[] args)
    {
        Student student = new Student { Scores = { 1, 2, 3 } }; // CS1925
    }
}