Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2017
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.38 KB | None | 0 0
  1. namespace ejemplo
  2. {
  3. class Program
  4. {
  5. static void Main()
  6. {
  7. string[] nombres = new string[10];
  8. int opcion, contador = 0;
  9. do
  10. {
  11. Console.Write("1. Añadir\n2. Insertar \n3. Borrar \n" +
  12. "4. Mostrar \n5. Salir\nOpción: ");
  13. opcion = Convert.ToInt32(Console.ReadLine());
  14. switch (opcion)
  15. {
  16. case 1://Añadir nombres
  17. Console.Write("¿Qué nombre quieres añadir?: ");
  18. nombres[contador] = Console.ReadLine();
  19. contador++;
  20. break;
  21. case 2://Insertar en una posicion
  22. Console.Write("¿En qué posición quieres insertar?: ");
  23. int posicionInsertar = Convert.ToInt32(Console.ReadLine());
  24. Console.Write("¿Qué nombre quieres insertar?: ");
  25. string nuevoNombre = Console.ReadLine();
  26. for (int i = contador; i >= posicionInsertar; i--)
  27. {
  28. nombres[i] = nombres[i - 1];
  29. }
  30. nombres[posicionInsertar] = nuevoNombre;
  31. contador++;
  32. break;
  33. case 3:// Borrar posicion
  34. Console.Write("¿Qué posición quieres borrar?: ");
  35. int posicionBorrar = Convert.ToInt32(Console.ReadLine());
  36. for (int i = posicionBorrar; i <= contador; i++)
  37. {
  38. nombres[i] = nombres[i + 1];
  39. }
  40. contador--;
  41. break;
  42. case 4://Mostrar
  43. for (int i = 0; i < contador; i++)
  44. {
  45. Console.WriteLine(nombres[i]);
  46. }
  47. break;
  48. case 5: break;//Salir
  49. default:
  50. Console.WriteLine("No es una opción válida.");
  51. break;
  52. }
  53. } while (opcion != 5);
  54.  
  55. Console.Write("Hasta pronto!");
  56. Console.ReadLine();
  57. }
  58. }
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement