C sharp - Ayuda con error c#

 
Vista:
sin imagen de perfil

Ayuda con error c#

Publicado por matias (5 intervenciones) el 23/05/2017 15:26:35
Hola que tal gente como estan tengo un pequeño problema al momento de ejecutar el programa ingreso ubicacion del archivo pero me da el mensaje de indice fuera de los limites de la matriz

el codigo
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
 
 
namespace ConsoleApplication15
{
    class lector
    {
        private System.Collections.ArrayList Registros = new System.Collections.ArrayList();
        private lectura lectura = new lectura();
 
 
        public lector()
        {
            this.Registros = new ArrayList();
            this.lectura = new lectura();
        }
        public void ejecutar()
        {
            leer();
            imprimirR();
        }
        private void leer()
        {
            string ubicacionarchivo;
            try
            {
                Console.WriteLine("dame la ubicacion del archivo");
                ubicacionarchivo = Console.ReadLine();
                System.IO.StreamReader lector = new System.IO.StreamReader(ubicacionarchivo);
 
                string lineas = Console.ReadLine();
 
                while (lineas != null)
                {
                    char[] delimitador = { ';' };
                    string[] palabras = lineas.Split(delimitador);
 
 
                    lectura L = new lectura();
                    L.lectura01 = palabras[0];
                    L.lectura02 = palabras[1];
                    L.lectura03 = palabras[2];
                    L.lectura04 = palabras[3];
                    L.lectura05 = palabras[4];
                    L.lectura06 = palabras[5];
 
                    Registros.Add(L);
                    lineas = Console.ReadLine();
                }
                lector.Close();
 
 
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
 
            }
            finally
            {
                Console.WriteLine("lectura terminda");
                Console.Write("presione una tecla"); Console.ReadLine();
            }
        }
 
        private void imprimirR()
        {
           foreach(object registro in Registros)
            {
                this.lectura = (lectura)registro;
                imprimirtodos();
            }
        }
        private void imprimirtodos()
        {
        Console.WriteLine("---------------------------");
        Console.WriteLine("lectura01"+ lectura.lectura01);
        Console.WriteLine("lectura02" + lectura.lectura02);
        Console.WriteLine("lectura03" + lectura.lectura03);
        Console.WriteLine("lectura04" + lectura.lectura04);
        Console.WriteLine("lectura05" + lectura.lectura05);
        Console.WriteLine("lectura06" + lectura.lectura06);
        }
    }
}

las class
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace ConsoleApplication15
{
    class lectura
 
    {
        public string lectura01;
        public string lectura02;
        public string lectura03;
        public string lectura04;
        public string lectura05;
        public string lectura06;
 
        public lectura()
 
        {
 
        }
 
    }
}

y el programa principal
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace ConsoleApplication15
{
    class Program
    {
        static void Main(string[] args)
        {
            lector programa = new lector();
            programa.ejecutar();
        }
    }
}

ayuda por favor no se por que me sale eso


el archivo de texto se encuentra guardado en el bin\debug del projecto
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder