如何判断list内是否存在这个元素

wctmac123 2017-07-29 01:57:59
List<Dictionary<string, string>> listdatas = new List<Dictionary<string, string>>();
list里面是一个Dictionary,dictionary里的内容是("groupname","默认组")
我现在要做的事情是在把dictionary添加到list里时候,查询dictionary里的groupname这个key对应对的value
请大神指教
...全文
2980 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
zhanglong_longlong 2017-07-31
  • 打赏
  • 举报
回复
Contains
  • 打赏
  • 举报
回复
wctmac123 2017-07-30
  • 打赏
  • 举报
回复
顶一下,求各位答案
wctmac123 2017-07-29
  • 打赏
  • 举报
回复
引用 6 楼 insus 的回复:
Contains这个方法可以判断List数据集中对象是否存在。
listdatas.Contains(dcdatas) 是可以判断,但是我这个dcdatats里有多个键值对,该如何呢?我只要判断字典里面其中一个键值对,而不是去匹配整个dcdatas是否存在
insus 2017-07-29
  • 打赏
  • 举报
回复
Contains这个方法可以判断List数据集中对象是否存在。
wctmac123 2017-07-29
  • 打赏
  • 举报
回复
引用 2 楼 yuankaiwsl 的回复:
感觉有问题,List<Dictionary<string, string>> listdatas = new List<Dictionary<string, string>>(); 是不是要写成List<KeyValuePair<string, string>> listdatas = new List<KeyValuePair<string, string>>(); 你的数据源是什么类型的?
因为我list里面有多个键值对,所以用dictionary
wctmac123 2017-07-29
  • 打赏
  • 举报
回复
引用 3 楼 hello__world3 的回复:
for(Dictionary<K, V> dictionary : listdatas ){ dictionary.get("键"); }
我的本意是,在第一次添加到list的时候,判断下list里的dic内部有没有groupname为授权组的值,有的话归纳起来 如果是全部添加好以后再循环list,这样显得有点繁琐
  • 打赏
  • 举报
回复
for(Dictionary<K, V> dictionary : listdatas ){ dictionary.get("键"); }
巴士上的邂逅 2017-07-29
  • 打赏
  • 举报
回复
感觉有问题,List<Dictionary<string, string>> listdatas = new List<Dictionary<string, string>>(); 是不是要写成List<KeyValuePair<string, string>> listdatas = new List<KeyValuePair<string, string>>(); 你的数据源是什么类型的?
  • 打赏
  • 举报
回复
遍历 listdatas

62,072

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧