C
C#2y ago
meizuflux

How do I use String.Format with a multidimensional array?

char[,] state = new char[3, 3] {
{'A', ' ', ' '},
{' ', ' ', ' '},
{' ', ' ', ' '}
};
//
// used like v I want the first column of the first row here
Console.WriteLine(String.Format(" -> {} ", state))
char[,] state = new char[3, 3] {
{'A', ' ', ' '},
{' ', ' ', ' '},
{' ', ' ', ' '}
};
//
// used like v I want the first column of the first row here
Console.WriteLine(String.Format(" -> {} ", state))
output should be A
8 Replies
Angius
Angius2y ago
Console.WriteLine($" -> {state[0, 0]}");
Console.WriteLine($" -> {state[0, 0]}");
meizuflux
meizufluxOP2y ago
Probably should have clarified, I know I can do that but with 9 elements it gets tedious Just curious if there was a better way
Angius
Angius2y ago
Use a loop then And don't use String.Format() for such simple things
meizuflux
meizufluxOP2y ago
Already wrote it out
Angius
Angius2y ago
Well, if you have a loop, what doesn't work about it?
meizuflux
meizufluxOP2y ago
It's more complicated than that, this is just an example No, I mean I already wrote it out by hand
Angius
Angius2y ago
There's very little a String.Format() can do that string interpolation cannot
meizuflux
meizufluxOP2y ago
Good to know Thanks for answering
Want results from more Discord servers?
Add your server