C
C#15mo ago
Arone

✅ How would i print a string value into this 2d array?

const int shipGridWidth = 5; const int shipGridHeight = 9; int[,] shipGrid = new int[shipGridWidth, shipGridHeight]; for (int y = 0; y < shipGridHeight; y++) { for (int x = 0; x < shipGridWidth; x++) { if (y == 0) shipGrid[x, y] = x+1; // Populate header index else { if (x == 0) shipGrid[x, y] = y + 1; // Populate row index else { //populate playing board shipGrid[x, y] = 0; shipGrid[2, 4] = 5; } } } } //Print Grid for (int y = 0; y < shipGridHeight; y++) { for (int x = 0; x < shipGridWidth; x++) { Console.Write("{0,6}",shipGrid[x, y]); } Console.WriteLine(); } Console.ReadLine();
6 Replies
Azrael
Azrael15mo ago
$paste
MODiX
MODiX15mo ago
If your code is too long, you can post to https://paste.mod.gg/ and copy the link into chat for others to see your shared code!
Azrael
Azrael15mo ago
$code
MODiX
MODiX15mo ago
Posting Code Snippets To post a code snippet type the following: ```cs // code here ``` Notes: - Get an example by typing $codegif in the chat. - Change the language by replacing cs with the language of your choice (for example sql or cpp). - If your code is too long, you can post it to https://paste.mod.gg/ and share the link.
Angius
Angius15mo ago
So... what doesn't work here?
Arone
AroneOP15mo ago
i wanted to try and print a string into the array but dw in my lesson today we kinda figured it out#

Did you find this page helpful?