Aman
New member
- Joined
- Oct 23, 2023
- Messages
- 3
- Programming Experience
- 1-3
C#:
namespace WinFormsApp1
{
public partial class Form1 : Form
{
public class class1
{
public List<Person> people { get; set; }
}
public class Person
{
public string name { get; set; }
public string addess { get; set; }
}
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
Person p = new Person();
p.name = "Test";
p.addess = "Test 2";
class1 data = new class1();
data.people.Add(p); // Error - object reference not set to an instance od an object
MessageBox.Show(data.people[0].name);
}
}
}
Last edited by a moderator: