I have a simple windows form application. Basically, I want to save the user's input of their ID number and name. I have a Person class:
class Person
{
private string nric;
private string name;
public Person(string nric, string name)
{
this.nric = nric;
this.name = name;
}
And the .cs file:
private void save_Click(object sender, EventArgs e)
{
List<Person> pList = new List<Person>();
Person p1 = new Person(nric.Text, name.Text);
pList.Add(p1);
using (TextWriter tw = new StreamWriter("PersonFile.txt"))
{
foreach (Person p in pList)
{
tw.WriteLine(p);
}
tw.Close();
}
}
When I tried to run the codes, this is the output shown in the PersonFile.txt:
Testing.Person
How do I make it such that the ID number and name would be displayed in the text file?