Siemka!
W jaki sposób dodać obiekt do listy w liscie?
Mam taki kod:
public class Person
{
public string name;
public string naz;
public List<Adress> lista;
public Person() { }
public Person(string name, string naz) {
this.name = name;
this.naz = naz;
}
}
public class Adress
{
public string nazwa;
public Adress() { }
public Adress(string nazwa)
{
this.nazwa = nazwa;
}
}
class Program
{
static void Main(string[] args)
{
List<Person> p = Data.patient;
p[0].lista.Add(new Adress("Adress"));
Console.WriteLine(p[0].lista[0].nazwa);
Console.ReadLine();
}
}
i w miejscu gdzie dodaję adres mam błąd {"Object reference not set to an instance of an object."}