C# add array to object -
i'm trying create simple object accept properties string , array.
this how i've tried done:
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; } }
but returns:
cannot initialize type 'excelsdraddin.usercontrolsdr.vars' collection initializer because not implement 'system.collections.ienumerable'
you try add list string. want list of strings
, should declare in vars
class.
public void addtoobject() { list<vars> variable = new list<vars>(); variable.add(new vars { id = "var1", names = new list<string>(){ "n1", "n2", "n3", "n4" } }); } public class vars { public string id { get; set; } public list<string> names { get; set; } }
run code here.
Comments
Post a Comment