我想創建一個簡單的對象,將接受作爲屬性的字符串和數組。C#添加數組到對象
這是怎麼了,我想完成這件事:
public void addToObject()
{
List<Vars> variable = new List<Vars>();
variable.Add(new Vars { Id = "var1", Name = { "n1", "n2", "n3", "n4" } });
}
public class Vars
{
public string id { get; set; }
public string name { get; set; }
}
但它返回:
Cannot initialize type 'ExcelSDRAddIn.UserControlSDR.Vars' with a collection initializer because it does not implement 'System.Collections.IEnumerable'
名稱是字符串,並要指定集合字符串 – jjj