I usually work with PHP and I’m just unable to create complex arrays in C#.
I’m trying to make an item generator like in Diablo 2 and I’m parsing a csv-file into a dictionary.
Here’s my dictionary as it looks at the moment:
public static Dictionary<int, Dictionary<int, string[]>> prefixes = new Dictionary<int, Dictionary<int, string[]>>();
The idea is that I’m grouping the rows in the csv-file into sub-dictionaries or what you’d call it based on a column in the file. I think it’s working fine, but I’m unable to see the contents of prefixes. My expected result is this:
Sorry, my tablet driver broke and my mouse drawing skills are awful.
In PHP I would just do print_r or whatever, but in C# I have no clue what do to.
I’m trying:
foreach (KeyValuePair<int, Dictionary<int,string[]>> prefixGroup in prefixes) {
foreach (KeyValuePair<int, string[]> groupRow in prefixGroup) {
foreach (string s in groupRow.Value) {
Debug.Log(s);
}
}
}
But that just gives me this error:
Assets/Scripts/Items/FileReader.cs(48,9): error CS1579: foreach statement cannot operate on variables of type `System.Collections.Generic.KeyValuePair<int,System.Collections.Generic.Dictionary<int,string[]>>' because it does not contain a definition for `GetEnumerator' or is not accessible
It’s not hard to see what’s not working from the error, but how do I make it work? I’ve googled for hours.
Also, if there’s a better way of doing this then please let me know.