Lets do some refactoring exercise together
Reduce the number of loops
If you look at your for
loops' iteration definitions
for (int i = 5; i < 120; i++)
for (int i = 1; i < 35; i++)
for (int i = 5; i < 120; i++)
for (int i = 1; i < 35; i++)
then you can see that you have only two different versions. So, you can combine those for
loops which has the same iteration definition
for (int i = 5; i < 120; i++)
{
Console.SetCursorPosition(i, 1);
Console.WriteLine('I');
Console.SetCursorPosition(i, 34);
Console.WriteLine('I');
}
for (int i = 1; i < 35; i++)
{
Console.SetCursorPosition(5, i);
Console.WriteLine("II");
Console.SetCursorPosition(119, i);
Console.WriteLine("II");
}
Simplify horizontal lines logic
Your first iteration is responsible to write 115 I
characters at 1st and the 34th line on the console.
Instead of writing 230 I
characters one by one (+ setting the cursor's position) you can write two 115 long strings:
Console.SetCursorPosition(5, 1);
Console.WriteLine(new string('I', 115));
Console.SetCursorPosition(5, 34);
Console.WriteLine(new string('I', 115));
Improving legibility by using constants
If you introduce some constants then it can highly improve the readability of your code by better expressing your intent
Constants
const int LeftMargin = 5, TopMargin = 1;
const int Height = 34, Width = 115;
const char HorizontalSymbol = 'I';
const string VerticalSymbol = "II";
Their usage
Console.SetCursorPosition(LeftMargin, TopMargin);
Console.WriteLine(new string(HorizontalSymbol, Width));
Console.SetCursorPosition(LeftMargin, Height);
Console.WriteLine(new string(HorizontalSymbol, Width));
for (int line = TopMargin; line <= Height; line++)
{
Console.SetCursorPosition(LeftMargin, line);
Console.WriteLine(VerticalSymbol);
Console.SetCursorPosition(LeftMargin + Width -1, line); //-1 cuz VerticalSymbol's length
Console.WriteLine(VerticalSymbol);
}