[Solved] How can i read from a text file line by line and add those strings to an array? [closed]


The array isnt initialized.

Try using List instead of array.

private void button2_Click(object sender, EventArgs e)
{
    List<int> citaj = new List<int>();
    string h;
    using(System.IO.StreamReader sr = new System.IO.StreamReader(@"text\brojac.txt")) 
    {
        while ((h = sr.ReadLine()) != null)
        {
            int number = 0;
            if (int.TryParse(h, out number)) 
                citaj.Add(number);
        } 
    } 
} 

solved How can i read from a text file line by line and add those strings to an array? [closed]