Search code examples
c#keyvaluepair

How can i get value of an object in a list of KeyValuePair


var list = new List<KeyValuePair<string, IObject>>(){};

I want to Console.WriteLine() the actual value of interface IObject from the list. How can I do that?


Solution

  • Depending on what you want to print. If IObject returns it's value in for example Info() method then it should look something like this.

    foreach (var kvp in list)
    {
        Console.WriteLine(kvp.Value.Info());
    }