I am reading numbers from file, but how can I make the program reading the numbers and saving in the array only the numbers that are not listed in the file several times and will give me the number of all the unique numbers in the file so I can use it later in the code?
private void button2_Click(object sender, EventArgs e)
{
System.IO.Stream myStream;
this.openFileDialog1.Filter = "TXT files|*.txt";
this.openFileDialog1.InitialDirectory = @"C:\";
if (this.openFileDialog1.ShowDialog() == DialogResult.OK) {
//CHECKING FOR EXCEPTIONS
try {
if ((myStream = this.openFileDialog1.OpenFile()) != null) {
System.IO.StreamReader myRead = new System.IO.StreamReader(myStream);
this.textBox2fayl.Text = myRead.ReadToEnd();
ia = this.textBox2fayl.Text.Split(' ').Select(int.Parse).ToArray();
//SHOW THE LENGHT OF THE ARRAY
//string s="";
// int size = ia.Length;
// foreach (int x in ia)
// s += x + "-";
// MessageBox.Show("Length="+size+","+s);
myRead.Close();
myStream.Close();
}
} catch (FormatException xx) {
MessageBox.Show("Файлът трябва да съдържа САМО цели числа, разделени с интервал! (" + xx.Message + ")");
ia = null;
} catch (Exception ex) {
MessageBox.Show("Файлът не може да бъде отворен.Грешка:" + ex.Message);
}
}
}