简体   繁体   中英

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?

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());
}

You can loop through the list items and print its values:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM