Необработанное исключение типа "System.ArgumentOutOfRangeException" - C#
Формулировка задачи:
Доброго времени суток. Программа делит строки файла на элементы. Затем записывает эти элементы в список.
Необработанное исключение типа "System.ArgumentOutOfRangeException"
Указывает на:
namespace ConsoleApplication1 {
class sotrudnik
{
public string fam;
public string im;
public string ot;
public int tnomer;
public string d;
public string department;
public string post;
}
class organization
{
public List<sotrudnik> x = new List<sotrudnik>();
public List<argument> y = new List<argument>();
public void Read2()
{
StreamReader stream = new StreamReader("d:/lab1.txt", System.Text.Encoding.Default);
string str;
int i = 0;
while (stream.EndOfStream == false)
{
str = stream.ReadLine();
var splitted = str.Split(' ');
Console.WriteLine("{0} {1} {2} {3} {4} {5}", splitted[0], splitted[1], splitted[2], splitted[3], splitted[4], splitted[5]);
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];
i++;
}
Console.WriteLine("Запись закончена");
stream.Close();
output();
}
public void output()
{
for (int i=0; i<x.Count; i++)
{
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);
}
Console.ReadKey();
}
class program {
static void Main(string[] args)
{
int j;//j-индекс меню,
organization c = new organization();
c.Read2();
}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
Листинг программы
x[i]