Ver Mensaje Individual
  #2 (permalink)  
Antiguo 05/06/2010, 09:01
Avatar de gedarufi
gedarufi
 
Fecha de Ingreso: diciembre-2008
Ubicación: Colombia
Mensajes: 540
Antigüedad: 15 años, 5 meses
Puntos: 22
Respuesta: Ayuda FileStream y StreamReader en C#

Yo lo haria asi
Código C#:
Ver original
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.IO;
  6.  
  7. namespace ConsoleApplication
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             FileStream Archivo = new FileStream(@"C:\Users\German\Desktop\Leer.txt", FileMode.Open, FileAccess.ReadWrite);
  14.             StreamReader Lectura = new StreamReader(Archivo);
  15.            
  16.             float Promedio = 0;
  17.             float Suma = 0;
  18.             List<int> Numeros = new List<int>();
  19.  
  20.             while (Lectura.ReadLine() != null)
  21.             {
  22.                 Numeros.Add(int.Parse(Lectura.ReadLine()));
  23.                 Suma = Suma + Numeros[Numeros.Count - 1];
  24.             }
  25.             Promedio = Suma / Numeros.Count;
  26.             Archivo.Close();
  27.             Lectura.Close();
  28.             Console.WriteLine("Se ecntraron {0} Elementos con una suma de {1} y Promedio {2:F} ",Numeros.Count,Suma,Promedio);
  29.             Console.ReadKey();
  30.         }
  31.     }
  32. }