private bool Readfile() { bool successfulRead = false; if (openFileDialog1.ShowDialog() == DialogResult.OK) { StreamReader streamReader = null; try { streamReader = new StreamReader(openFileDialog1.FileName); string[] line1 = null; string line2 = null; while (!streamReader.EndOfStream) { line1 = streamReader.ReadLine().Split(';'); line2 = streamReader.ReadLine(); string name = line1[0]; int.TryParse(line1[1], out int price); string description = line2; Phone phone = new Phone(name, price, description); shop.AddPhone(phone); } successfulRead = true; } catch (Exception e) { MessageBox.Show("A fájl olvasása során hiba keletkezett!" + Environment.NewLine + e.Message, "Hiba"); } finally { if (streamReader != null) { streamReader.Close(); } } } return(successfulRead); }