How to solve Object reference not set to an instance of an object.?
This question already has an answer here:
您需要首先初始化列表:
protected List<string> list = new List<string>();
I think you just need;
List<string> list = new List<string>();
list.Add("hai");
There is a difference between
List<string> list;
and
List<string> list = new List<string>();
When you didn't use new
keyword in this case, your list
didn't initialized. And when you try to add it hai
, obviously you get an error.
上一篇: NullReferenceException的含义是什么?
下一篇: 如何解决未将对象引用设置为对象的实例?