1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

New to c#, trying to figure out IO

Discussion in 'C#' started by LevyDee, Aug 28, 2010.

  1. LevyDee

    LevyDee New Member

    Aug 28, 2010
    Likes Received:
    Trophy Points:
    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 = tr.ReadLine();



    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.

Share This Page