naquo

Ejercicio para Gruber

May 28th, 2014
308
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.20 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3.  
  4. namespace BORRAR
  5. {
  6.     class Program
  7.     {
  8.         static void Main(string[] args)
  9.         {
  10.             int opción;
  11.             List<String> lista = new List<string>();
  12.             while (true)
  13.             {
  14.                 Console.Clear();
  15.                 Console.WriteLine("---CONTENIDO DE LA LISTA---");
  16.                 foreach (string palabra in lista)
  17.                     Console.WriteLine(palabra);
  18.                 Console.WriteLine("---FIN DEL CONTENIDO---");
  19.                 Console.WriteLine("1. Añadir");
  20.                 Console.WriteLine("2. Borrar");
  21.                 Console.WriteLine("3. Modificar");
  22.                 Console.WriteLine("0. Salir");
  23.                 Console.Write("Ingrese la opción: ");
  24.                 opción = Convert.ToInt32(Console.ReadLine());
  25.                 if (opción == 0)
  26.                     break;
  27.                 switch (opción)
  28.                 {
  29.                     case 1:
  30.                         Console.Write("Ingrese el texto: ");
  31.                         lista.Add(Console.ReadLine());
  32.                         break;
  33.                     case 2:
  34.                         for(int i = 0; i < lista.Count; i++)
  35.                             Console.WriteLine("{0,2}. {1}", i, lista[i]);
  36.                         Console.Write("Ingrese número del texto a eliminar: ");
  37.                         opción = Convert.ToInt32(Console.ReadLine());
  38.                         if(opción >= 0 && opción < lista.Count)
  39.                             lista.RemoveAt(opción);
  40.                         break;
  41.                     case 3:
  42.                         for(int i = 0; i < lista.Count; i++)
  43.                             Console.WriteLine("{0,2}. {1}", i, lista[i]);
  44.                         Console.Write("Ingrese número del texto a modificar: ");
  45.                         opción = Convert.ToInt32(Console.ReadLine());
  46.                         if(opción >= 0 && opción < lista.Count) {
  47.                             Console.Write("Ingrese el texto: ");
  48.                             lista[opción] = Console.ReadLine();
  49.                         }
  50.                         break;
  51.                 }
  52.             }
  53.         }
  54.     }
  55. }
Advertisement
Add Comment
Please, Sign In to add comment