简体   繁体   English

如何检索一行中有字典(C#)的唯一项目的值?

[英]How can I retrieve the value of the only item I have an a Dictionary (C#) in one line?

How can I retrieve the value of the only item I have an a Dictionary (C#) in one line? 如何检索一行中有字典(C#)的唯一项目的值? Is this possible? 这可能吗?

dictionary.Single().Value

Single throws an exception if the dictionary doesn't contain exactly one element (if you don't like this behavior, use First() instead). 如果字典不完全包含一个元素,则Single会引发异常(如果您不喜欢这种行为,请改用First() )。 If you're sure you're going to put a single item in a dictionary, why aren't you simply using a variable? 如果确定要在字典中放入单个项目,为什么不简单地使用变量呢?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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