© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•3y ago•
6 replies
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();
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

✅ How can I print a 2D array
C#CC# / help
4y ago
Defining and checking a 2D string array
C#CC# / help
2y ago
❔ Split 2D array into 4 chunks.
C#CC# / help
3y ago
✅ How can I replace a value in a 2D array, then refresh a datagridview with the new array
C#CC# / help
4y ago