1

I am trying to initialize a list in a class but it thows object not set to an instance of an object

Objs

    class te1
    {
       public t2 test2 {get; set;}
       public string tst {get; set;}
    }
    class t2
    {
       public List<string> da {get; set;}
    }

Calling (this is what throws the error)

  var data = new te1();
  data.t2.da = new List<string>();

1 Answers1

1

you need to initialize test2 as well before using da listIt should be like,

var data = new te1();
data.test2  = new t2();
data.test2.da = new List<string>();
Sajeetharan
  • 186,121
  • 54
  • 283
  • 331