Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace ejemplo
- {
- class Program
- {
- static void Main()
- {
- string[] nombres = new string[10];
- int opcion, contador = 0;
- do
- {
- Console.Write("1. Añadir\n2. Insertar \n3. Borrar \n" +
- "4. Mostrar \n5. Salir\nOpción: ");
- opcion = Convert.ToInt32(Console.ReadLine());
- switch (opcion)
- {
- case 1://Añadir nombres
- Console.Write("¿Qué nombre quieres añadir?: ");
- nombres[contador] = Console.ReadLine();
- contador++;
- break;
- case 2://Insertar en una posicion
- Console.Write("¿En qué posición quieres insertar?: ");
- int posicionInsertar = Convert.ToInt32(Console.ReadLine());
- Console.Write("¿Qué nombre quieres insertar?: ");
- string nuevoNombre = Console.ReadLine();
- for (int i = contador; i >= posicionInsertar; i--)
- {
- nombres[i] = nombres[i - 1];
- }
- nombres[posicionInsertar] = nuevoNombre;
- contador++;
- break;
- case 3:// Borrar posicion
- Console.Write("¿Qué posición quieres borrar?: ");
- int posicionBorrar = Convert.ToInt32(Console.ReadLine());
- for (int i = posicionBorrar; i <= contador; i++)
- {
- nombres[i] = nombres[i + 1];
- }
- contador--;
- break;
- case 4://Mostrar
- for (int i = 0; i < contador; i++)
- {
- Console.WriteLine(nombres[i]);
- }
- break;
- case 5: break;//Salir
- default:
- Console.WriteLine("No es una opción válida.");
- break;
- }
- } while (opcion != 5);
- Console.Write("Hasta pronto!");
- Console.ReadLine();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement