C
Join ServerC#
help
How do I use String.Format with a multidimensional array?
Mmeizuflux2/23/2023
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
AAngius2/23/2023
Console.WriteLine($" -> {state[0, 0]}");
Mmeizuflux2/23/2023
Probably should have clarified, I know I can do that but with 9 elements it gets tedious
Mmeizuflux2/23/2023
Just curious if there was a better way
AAngius2/23/2023
Use a loop then
AAngius2/23/2023
And don't use
String.Format()
for such simple thingsMmeizuflux2/23/2023
Already wrote it out
AAngius2/23/2023
Well, if you have a loop, what doesn't work about it?
Mmeizuflux2/23/2023
It's more complicated than that, this is just an example
Mmeizuflux2/23/2023
No, I mean I already wrote it out by hand
AAngius2/23/2023
There's very little a
String.Format()
can do that string interpolation cannotMmeizuflux2/23/2023
Good to know
Mmeizuflux2/23/2023
Thanks for answering