I have a Dictionary
with some simple string,string
value pairs. The problem is that sometimes the key has to be empty for multiple items, which gives a dictionary error ->
this key already exists.
Is there another class for this?
Also, I'm using .NET 2.0 so I can't use the Tuple class ...
while (nav.MoveToNext())
{
if (nav != null)
{
if (!String.IsNullOrEmpty(nav.Value))
{
if (nav.HasChildren)
{
navChildren = nav.Clone();
navChildren.MoveToFirstChild();
if (navChildren != null)
if (!veldenToSkip.Contains(nav.LocalName.Trim().ToLower())
&& !nav.LocalName.StartsWith("opmerkingen_"))
itemTable.Add(nav.LocalName.Replace("_", " "), navChildren.Value);
//normal key and value
while (navChildren.MoveToNext())
{
if (!veldenToSkip.Contains(nav.LocalName.Trim().ToLower()))
{
if (navChildren != null)
{
if (!String.IsNullOrEmpty(navChildren.Value))
{
itemTable.Add("", navChildren.Value);
//Add blank keys
}
}
}
}
}
}
}
}
I only want a structure like this:
value1 value2
value3 value4
value5
value6
value7 value8
...
you could implement the ILookup interface ...
wrap a Dictionary< TKey,List< TValue > >
Because having multiple values with the same key sort of negates the utility of a dictionary, a List of KeyValuePairs frequently makes more sense:
List<KeyValuePair<string, string>> itemTable = new List<KeyValuePair<string, string>>();
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