Hi guys, as the title suggest, Im new to c#. I have a text file with 5 lines of text in it. Im trying to read each line and throw it into an array of string type.
But Im having problems.
private void button4_Click(object sender, EventArgs e)
{
songs = new string[5];
OpenFileDialog grabSong = new OpenFileDialog();
if (grabSong.ShowDialog() == DialogResult.OK)
{
playlist = grabSong.FileName; //playlist is just a private member of string type.
TextReader tr = new StreamReader(playlist);
for (int i = 0; i != 5; i++)
{
songs[i] = tr.ReadLine();
}
tr.Close();
}
}
Edit: I debugged it when I first tryed to check if the array was being filled properly, and it wasnt. Just debugged again and it is working fine now. Weird =p.
But Ill still post this if anyone can give some better suggestions on how to do this. For instance, in my for conditions, I cant say, (int i = 0; i != songs.count; i++) like I would be able to in c++.
Any tips? Thanks.