Hi Guys, I created a program that generate random numbers and then I stored the generated number in a textfile. I want to retrieves the value stored in the textfile and display the largest and smallest value.
Can anyone help me out?
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
namespace WindowsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
string[] alllines = File.ReadAllLines("number.txt");
int maxx = 0;
int maxy = 0;
foreach (string line in alllines)
{
string [] oneline = line.Split(' ');
if (Convert.ToInt16(oneline[0]) > maxx)
{
maxx = Convert.ToInt16(oneline[0]);
}
if (Convert.ToInt16(oneline[1]) > maxy)
{
maxy = Convert.ToInt16(oneline[1]);
}
}
textBox1.Text = maxx.ToString();
textBox2.Text = maxy.ToString();
}
}
}
Here is how my generated number looks like inside the textfile:
68 16 89 96 89
92 76 13 16 68
62 7 33 76 31
I just tried for the first 2 lines but I am stuck. I have no clue what should I do.