I am trying to convert Dictionary<string, string> to multidimensional array.
The items inside multidimentional array should be in quotes.
So far I get this ["[mary, online]","[alex, offline]"].
But the output should be something like [["mary", "online"], ["alex", "offline"]]. Please help.
public void sendUpdatedUserlist(IDictionary<string, string> message)
{
string[] array = message
.Select(item => string.Format("[{0}, {1}]", item.Key, item.Value))
.ToArray();
}
If you insist on 2d array (string[,], not jagged string[][]) you can create the array and fill it row by row:
string[,] array = new string[message.Count, 2];
int index = 0;
foreach (var pair in message) {
array[index, 0] = pair.Key;
array[index++, 1] = pair.Value;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With