-1

I'm creating the following List with a KeyValuePair which contains an object and another List:

var testList = new List<KeyValuePair<classTypeObject, List<DataTypeObject>>>
{
    new KeyValuePair<classTypeObject, List<DataTypeObject>>(classTypeObject.Mountain, new List<DataTypeObject>()),
    new KeyValuePair<classTypeObject, List<DataTypeObject>>(classTypeObject.City, new List<DataTypeObject>()),
};

How can I add items to the List for example to the second entry with the Key=classTypeObject.City?

stuartd
  • 70,509
  • 14
  • 132
  • 163
Philies
  • 233
  • 1
  • 4
  • 15

1 Answers1

3

It would be:

testList[1].Value.Add(....)

Value = List Key = classTypeObject

If your key is a little bit more complex, you could use lambda expressions:

testList.Where(x => x.Key == classTypeObject.City).First().Value.Add(...)
kaliba
  • 230
  • 2
  • 12