New to c#, trying to figure out IO

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

  1. LevyDee

    LevyDee New Member

    Joined:
    Aug 28, 2010
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    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();
    }

    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.
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice