Null Reference Exception for Class Lists

后端 未结 3 1309
隐瞒了意图╮
隐瞒了意图╮ 2020-12-12 05:16

I am new to programming and am running into an issue when creating a class with a list property of another class and then accessing it in main. I am getting the exception \"

3条回答
  •  余生分开走
    2020-12-12 05:39

    You need to initialize the Boolist.bookList in the default ctor:

    class BookList
    {
        public BookList() { bookList = new List; } // <<<<
        public List bookList { get; set; }
    }
    

提交回复
热议问题