I'm completely new to object orientated programming in C# and was wondering what the best way of using a 2nd form to enter details that are used to create a new instance of an object that exists on the first form.
Do I just pass the variables back to the form and create the new instance on the new form. Just wondering the best way....
Basic code for form1
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
Form2 frm2 = new Form2();
frm2.ShowDialog();
}
}
class person
{
public string Name { get; set; }
public int age { get; set; }
}
Basic code for Form2
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
// How do I create a new instance of person using these variables
string name = "Neil";
int age = 42;
this.Close();
}
}
Any help greatly Appreciated