Advertisement
Mastercpp

registros

Aug 30th, 2015
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.22 KB | None | 0 0
  1. /*
  2.  * Creado por Tito Flavio RD
  3.  * Fecha: 30/08/2015
  4.  *
  5.  *
  6.  *
  7.  */
  8.  
  9.  
  10.  // Todas las librerias son necesarias
  11.  
  12. using System;
  13. using System.Collections;
  14. using System.Collections.Generic;
  15. using System.IO;
  16. namespace pruebas
  17. {
  18.     class Program{
  19.         public static void Main(string[] args){
  20.             // todos los datos que el usuario introduzca lo voy a guardar en un fichero de texto
  21.             // por eso voy  a usar StreamWriter en vez de TexWriter
  22.             StreamWriter escribir_datos = File.AppendText("registro.txt");
  23.             //Esto es para leer todo el registro pero si lo hago me manda un
  24.             // aviso de que no se puede leer por que ya esta uso
  25.             // Si descomentamos la linea 26 y las lineas 49 hasta la 57  tendremos problemas
  26.             //TextReader leer_datos = new StreamReader("registro.txt");
  27.             // Hashtable es como un array asociativo en php y c++ (Claves y Valores)
  28.             Hashtable asoc = new Hashtable();
  29.             //aqui le pregunto al usuario cuantos estudiantes va a registrar
  30.             Console.WriteLine("Cuantos estudiantes quieres registrar: ");
  31.             int cantidad = int.Parse(Console.ReadLine());  //creo una variable cantidad
  32.             int [] id= new int [cantidad];  // aqui creo Arreglos/vectores con la cantidad de elementos
  33.             string [] nombres = new string[cantidad]; // que tenga la variable cantidad
  34.            
  35.             for(int i = 0; i<cantidad; i++){
  36.                 Console.WriteLine("ingrese el id del {0} estudiante ",i+1);
  37.                 id[i] = int.Parse(Console.ReadLine());
  38.                 Console.WriteLine("ingrese el nombres del {0} estudiante ",i+1);
  39.                 nombres[i] = Console.ReadLine();
  40.                 asoc[id[i]]=nombres[i];
  41.                 escribir_datos.WriteLine("Id: "+id[i] + "-> "+"Nombre: "+nombres[i]); // esta linea no servira para guardar
  42.                 Console.Clear();// ESto es para limpiar la consola  // estos valores en un fichero
  43.             }
  44.             escribir_datos.Close();
  45.            
  46.            
  47.            
  48.             // desde la linea 45 hasta la 50
  49.             /*
  50.             Console.WriteLine("Quieres ver todo los datos de los alumnos \n1-si 2-no");
  51.             int opcion = int.Parse(Console.ReadLine());
  52.             if(opcion == 1){
  53.                 Console.Clear();
  54.                 Console.WriteLine("\t\t\tTodos los Datos de los alumnos");
  55.                 Console.WriteLine(leer_datos.ReadToEnd());
  56.             }
  57.             */
  58.            
  59.             Console.Write("Press any key to continue . . . ");
  60.             Console.ReadKey(true);
  61.         }
  62.     }
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement