我想这样的代码:在c#中的对象的动态数组(或列表)?
private List<book> books;
//private book[] books;
.
.
.
private void button1_Click(object sender, EventArgs e)
{
books.Add(new book(book_name.Text));
//book[0]=new book(book_name.Text);
}
,但我得到这个错误:
'Object reference not set to an instance of an object.'
我该怎么办?我想通过事件动态创建对象。
读取错误消息,爱的错误消息。这个特定的错误意味着你正在执行'expr.member',其中'expr'的计算结果为null。在这种情况下,“书”是因为它从来没有被赋予一个值(一个*新的*列表,也许?)。 – 2011-12-28 03:27:44
(是否有一个通用的NullReferenceException后,我们可以关闭所有这些重复的?: - /) – 2011-12-28 03:29:15
http://stackoverflow.com/questions/5620678/nullreferenceexception-no-stack-trace-where-to-start,http: //stackoverflow.com/questions/4719047/why-doesnt-nullreferenceexception-contain-information-about-what-is-null,http://stackoverflow.com/questions/1031336/what-is-the-meaning-of-的NullReferenceException – 2011-12-28 03:32:30