I have the following string pattern: 1:2,2:3.
It looks like an array in one line:
First element: 1:2
Second element:2:3
I want to analyze it and create a dictionary:
1,2 // 0 element in Dictionary
2,3 // 1 element in Dictionary
This is my code:
Dictionary<int,int> placesTypes = new Dictionary<int, int>();
foreach (var place in places.Split(','))
{
var keyValuePair = place.Split(':');
placesTypes.Add(int.Parse(keyValuePair[0]), int.Parse(keyValuePair[1]));
}
Is there a better way to do this?
Thank.
source
share