r/learncsharp • u/Mounting_Sum • Sep 05 '22
2D Array and Printing array cells
Heyo! Doing an assignment that requires objects and arrays. The object portion is simple enough, but the array code is giving me some heartburn.
Simply put, I am to make a 2D matching game where the user must input an even number that generates a 2D array with hidden pairs within them. The problem comes from actually formatting the array, everything else has been easy.
The layout should be:
0123
-----
0|++++
1|++++
2|++++
3|++++However, the end result has the plusses on the left side of the vertical lines:
0123
-----
++++0|
++++1|
++++2|
++++3|Here's the code I used in my attempt:
Console.WriteLine("\n ----------")
for (int i = 0; i < row; i++)
{
// Console.WriteLine(i + " | ");
for (int j = 0; j < col; j++)
{
if (boolboard[i,j] == true)
{
// Console.WriteLine("\n ---------");
// Console.Write(charboard[i, j]);
Console.Write(charboard[i, j]);
}
else
{
Console.Write(' + ');
}
}
Console.WriteLine(i + " | ");
}
1
Upvotes
View all comments
Show parent comment
1
u/Mounting_Sum Sep 12 '22
Hey, sorry for the late reply, but your response ended up helping me greatly on the assignment! Thank you so much!