I'm trying to create a method that draws a rectangle like this:
--------------
| |
| ********** |
| ********** |
| ********** |
| ********** |
| ********** |
| ********** |
| ********** |
| ********** |
| |
--------------
I want to display the whole array matrix in console, but when I try to run the program, I get this error:
Unhandled Exception: System.IndexOutOfRangeException: Index was outside the bounds of the array.
I was trying to fix this for hours, but can't find the problem. Here's my code:
public static class Canvas
{
public static char[,] Draw (uint width, uint height)
{
char[,] page = new char[width + 4, height + 4];
for (uint i = 1; i < width + 3; ++i)
{
for (uint j = 1; j < height + 3; ++j)
{
page[i, j] = '1';
}
}
for (uint i = 0; i < width + 5; ++i)
{
page[0, i] = '-';
}
for (uint i = 0; i < width + 5; ++i)
{
page[height + 4, i] = '-';
}
for (uint j = 1; j < height + 4 ++j)
{
page[j, 0] = '|';
}
for (uint j = 1; j < height + 4; ++j)
{
page[j, width + 4] = '|';
}
return page;
}
}