Необработанное исключение типа "System.ArgumentOutOfRangeException" - C#

Узнай цену своей работы

Формулировка задачи:

Доброго времени суток. Программа делит строки файла на элементы. Затем записывает эти элементы в список.
Листинг программы
  1. namespace ConsoleApplication1 {
  2. class sotrudnik
  3. {
  4. public string fam;
  5. public string im;
  6. public string ot;
  7. public int tnomer;
  8. public string d;
  9. public string department;
  10. public string post;
  11. }
  12. class organization
  13. {
  14. public List<sotrudnik> x = new List<sotrudnik>();
  15. public List<argument> y = new List<argument>();
  16. public void Read2()
  17. {
  18. StreamReader stream = new StreamReader("d:/lab1.txt", System.Text.Encoding.Default);
  19. string str;
  20. int i = 0;
  21. while (stream.EndOfStream == false)
  22. {
  23. str = stream.ReadLine();
  24. var splitted = str.Split(' ');
  25. Console.WriteLine("{0} {1} {2} {3} {4} {5}", splitted[0], splitted[1], splitted[2], splitted[3], splitted[4], splitted[5]);
  26. x[i].fam=splitted[0]; x[i].im=splitted[1]; x[i].ot=splitted[2]; x[i].tnomer = Int32.Parse(splitted[3]); x[i].department = splitted[4]; x[i].post = splitted[5]; x[i].d = splitted[6];
  27. i++;
  28. }
  29. Console.WriteLine("Запись закончена");
  30. stream.Close();
  31. output();
  32. }
  33. public void output()
  34. {
  35. for (int i=0; i<x.Count; i++)
  36. {
  37. Console.WriteLine("{0} {1} {2} {3} {4} {5} {6} /n", x[i].fam, x[i].im, x[i].ot, x[i].tnomer, x[i].department, x[i].post, x[i].d);
  38. }
  39. Console.ReadKey();
  40. }
  41. class program {
  42. static void Main(string[] args)
  43. {
  44. int j;//j-индекс меню,
  45. organization c = new organization();
  46. c.Read2();
  47. }
Необработанное исключение типа "System.ArgumentOutOfRangeException" Указывает на:
Листинг программы
  1. x[i].fam=splitted[0]; x[i].im=splitted[1]; x[i].ot=splitted[2]; x[i].tnomer = Int32.Parse(splitted[3]); x[i].department = splitted[4]; x[i].post = splitted[5]; x[i].d = splitted[6];

Решение задачи: «Необработанное исключение типа "System.ArgumentOutOfRangeException"»

textual
Листинг программы
  1. x[i]

ИИ поможет Вам:


  • решить любую задачу по программированию
  • объяснить код
  • расставить комментарии в коде
  • и т.д
Попробуйте бесплатно

Оцени полезность:

11   голосов , оценка 4.273 из 5

Нужна аналогичная работа?

Оформи быстрый заказ и узнай стоимость

Бесплатно
Оформите заказ и авторы начнут откликаться уже через 10 минут
Похожие ответы