I am trying to workout to see how I can access list items from a different class and to update the same, I have my code below for clarification.
class list
{
private List<Person> people;
public List<Person> People
{
get { return people; }
set { people = value; }
}
}
public partial class Form2 : Form
{
Person p = new Person();
list l = new list();
p.Name = textBox1.Text;
p.Streetaddress = textBox2.Text;
p.Email = textBox3.Text;
p.Birthday = dateTimePicker1.Value;
p.AdditionalNotes = textBox4.Text;
l.People.Add(p);
listView2.Items.Add(p.Name);
}
there is Person class which has instance variables Name, Streetaddress etc.
Getting an error
Nullreference exception was unhandled
Please help me..
You need to instantiate the inner
List<Person>when the List class is instantiated. Otherwise it will be null.