If I have a 2D array like this: http://img360.imageshack.us/img360/8035/magicsquareuu8.jpg
How do I add the +--+-- etc
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
RyanPosted Mar 26, 2008, 7:55 PM
Thanks
AlanPosted Mar 26, 2008, 7:10 PM
That image looks to me like a snapshot of a console application.
If so, this code should reproduce it:
using System;
class Test
{
static void Main()
{
int[,] ia = new int[3,3]{{2,9,4},{7,5,3},{6,1,8}};
Console.Clear();
string horizontal = "+--+--+--+";
string vertical = "| ";
Console.WriteLine(horizontal);
for(int i = 0; i < 3; i++)
{
for(int j = 0; j < 3; j++)
{
Console.Write(vertical);
Console.Write(ia[i,j]);
}
Console.WriteLine(vertical);
Console.WriteLine(horizontal);
}
Console.ReadKey();
}
}