asp.net - How to add array of Objects of a class to List of type <x> where x is the same class in C# -
am have class, x
. have created array of objects, , list of type of same class.
eg:
public class test : iextensibledataobject { int a; string b; [datamember(name = "a", isrequired = false, order = 1)] public int { { return a; } set { value = a; } } [datamember(name = "b", isrequired = false, order = 2)] public string b { { return b; } set { value = b; } } }
the object array created like
test[] test1 = new test[2]; list<test> test2 = new list<test>(); test1[0].a = 1; test1[0].b = "t"; test1[1].a = 2; test1[1].b = "y"; test2.add(test1);
this line:
test2.add(test1);
is not working. error
"object reference not set instance of object".
test1[0]
null
.
need create instance before can set properties.
also, can add()
test[]
list<test[]>
(a list of arrays).
if want add of objects in array, call addrange()
.
Comments
Post a Comment