If I have a 2D array like this: http://img360.imageshack.us/img360/8035/magicsquareuu8.jpg
How do I add the +--+-- etc
Dumb/easy question
2 Answers
Know the answer? Post it. Somebody with the same question will find it here.
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend4days leftRegister
AlanRank #669 · 3.6K reputationPosted Mar 26, 2008, 3:10 PM EDT
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();
}
}
Ryan3 reputationPosted Mar 26, 2008, 3:55 PM EDT
Thanks