User-1838255255 posted
Hi Ash93,
According to your description, i think this issue is belong to winform project, here is asp.net forum, please check the following code:
Sample Code:
private void button1_Click(object sender, EventArgs e)
{
string fileName = @"D:\McTextFile.txt";
int count = TotalLines(fileName);
int[] necount = new int[count];
int i = 0;
using (StreamReader r = new StreamReader(fileName))
{
String input;
while ((input = r.ReadLine()) != null)
{
necount[i] = Convert.ToInt32(input);
i++;
}
}
Random random = new Random();
int start2 = random.Next(0, necount.Length);
textBox1.Text = necount[start2].ToString();
}
public int TotalLines(string filePath)
{
using (StreamReader r = new StreamReader(filePath))
{
int i = 0;
while (r.ReadLine() != null) { i++; }
return i;
}
}
txt file:
12
20
48
25
90
89
Best Regards,
Eric Du