选择KeyValuePair列表的值 [英] Select Value of List of KeyValuePair

查看:39
本文介绍了选择KeyValuePair列表的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何根据检查键值从键值对列表中选择值

How can i select the value from the List of keyvaluepair based on checking the key value

List<KeyValuePair<int, List<Properties>> myList = new List<KeyValuePair<int, List<Properties>>();

我想在这里获得

list myList[2].Value when myLisy[2].Key=5.

我该如何实现?

推荐答案

如果仍然需要使用列表,我将使用

If you need to use the List anyway I'd use LINQ for this query:

var matches = from val in myList where val.Key == 5 select val.Value;
foreach (var match in matches)
{
    foreach (Property prop in match)
    {
        // do stuff
    }
}

您可能需要检查 match 是否为空.

You may want to check the match for null.

这篇关于选择KeyValuePair列表的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆