I have a class Friend:
public class Friend
{
public string friendName;
public string friendStreet;
public string friendCity;
public string friendState;
public string friendZip;
public Friend()
{
}
}
and I am using a ArrayList called friendArray.
I have a text file that is formatted like this:
My Name
My Street
My City
My State
My Zip
My Name
My Street
My City
My State
My Zip
etc......
So I want to be able to read the text file (all addresses) into the arrayList. But I am having a brain fart. ;)
I am keeping a counter of the records on my GUI so when I add a new address it will increase by one and when I delete it will decrease so I always know how many records are in the ArrayList.
When I try my code it will read the 10 lines and then say that there are 10 records. So its not quite putting the things where they should go.
Also I am also trying to add each FriendName from the arrayList to display in a ListBox, I tried a foreach but did not quite work either.
Any ideas?
private void menuOpen_Click(object sender, System.EventArgs e)
{
if(File.Exists("AddressList.txt"))
{
inFile = new StreamReader("AddressList.txt");
string line = "";
while((line = inFile.ReadLine())!= null)
{
friendArray.Add(line);
}
//foreach(Friend fr in friendArray)
//{
// lstAddresses.Items.Add(fr.friendName);
//}
}
else
{
MessageBox.Show("File not found");
}
}