I found it fun, so I've put this way, with only one cycle:
public static void Main (string[] args)
{
int Ancho, Alto; string Asteriscos = null;
Console.Write("Escriba el ancho: "); // Pedimos la anchura.
if (!int.TryParse(Console.ReadLine(), out Ancho))
return;
Console.Write("Escriba el alto: "); // Pedimos altura
if (!int.TryParse(Console.ReadLine(), out Alto))
return;
Asteriscos = new string('*', Ancho); // Creamos los asteriscos bonitos.
for (int i = 0; i < Alto; i++)
{
// Imprimimos asteriscos como sea necesario.
if (i == 0 || i == (Alto - 1))
Console.WriteLine(Asteriscos);
else
Console.WriteLine("*{0," + (Ancho - 2) + "}*", ' ');
}
}
The only thing that this does is write a value or another depending on the value of the cycle variable ( i
), if it is in the first or last position, write a lot of asterisks, otherwise, only write 2 asterisks and format the output to make the shape.
Notice how to get the input values, they do not control the entry of a negative value or if the value of the width or height is valid to make the figure.
Some results:
Escriba el ancho: 5 Escriba el ancho: 10
Escriba el alto: 5 Escriba el alto: 6
***** **********
* * * *
* * * *
* * * *
***** * *
**********
Here is a repl.it
Greetings:)