If you want to fill the whole console window with your characters a possible way to go is to move back your cursor to the 0,0 position.
Example:
Console.CursorVisible = false;
for(int i = 0; i < Console.WindowHeight * Console.WindowWidth; i ++)
{
Console.Write((i / Console.WindowWidth) % 10); // print your stuff
}
Console.SetCursorPosition(0, 0);
Console.ReadKey();
So you could do it like this in your method:
private void DumpCharacters()
{
for (int y = 0; y < yMax; y++)
{
string line = string.Empty;
for (int x = 0; x < xMax; x++)
{
line += characters[x, y];
}
Console.SetCursorPosition(0, y);
Console.Write(line);
}
Console.SetCursorPosition(0, 0);
}
Notice that you don't have to substract one from yMax. It is because now you can use the last line of the Console screen too.
Here is the full code to generate the desired outcome:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleChar
{
class Program
{
static void Main(string[] args)
{
Console.Title = "Stackoverflow - Super example";
Console.CursorVisible = false;
int yMax = Console.WindowHeight;
int xMax = Console.WindowWidth;
char[,] characters= new char[Console.WindowWidth, Console.WindowHeight];
for (int i = 0; i < Console.WindowWidth; i++ )
{
for (int j = 0; j < Console.WindowHeight; j++)
{
char currentChar = ' ';
if((i == 0) || (i == Console.WindowWidth - 1))
{
currentChar = '║';
}
else
{
if((j == 0) || (j == Console.WindowHeight - 1))
{
currentChar = '═';
}
}
characters[i, j] = currentChar;
}
}
characters[0, 0] = '╔';
characters[Console.WindowWidth-1, 0] = '╗';
characters[0, Console.WindowHeight - 1] = '╚';
characters[Console.WindowWidth - 1, Console.WindowHeight - 1] = '╝';
for (int y = 0; y < yMax ; y++)
{
string line = string.Empty;
for (int x = 0; x < xMax; x++)
{
line += characters[x, y];
}
Console.SetCursorPosition(0, y);
Console.Write(line);
}
Console.SetCursorPosition(0, 0);
}
}
}