急急急!dictionary中如何通过value 来获取相应的key

c#编程dictionary中如何通过value 来获取相应的key

当年话下
浏览 1573回答 2
2回答

12345678_0001

Demo:var&nbsp;dic&nbsp;=&nbsp;new&nbsp;Dictionary<string,&nbsp;int>() { &nbsp;&nbsp;&nbsp;&nbsp;{"a",1}, &nbsp;&nbsp;&nbsp;&nbsp;{"b",2}, &nbsp;&nbsp;&nbsp;&nbsp;{"c",3}, &nbsp;&nbsp;&nbsp;&nbsp;{"d",1} };foreach&nbsp;(var&nbsp;item&nbsp;in&nbsp;dic) {&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;(item.Value&nbsp;==&nbsp;1) &nbsp;&nbsp;&nbsp;&nbsp;{ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Console.WriteLine(item.Key); &nbsp;&nbsp;&nbsp;&nbsp;} }

阿波罗的战车

Dictionary<string,string>&nbsp;dic&nbsp;=newDictionary<string,string>() {{"1","one"},};var&nbsp;key_by_value&nbsp;=&nbsp;dic.Where(p&nbsp;=>&nbsp;p.Value=="one").Select(p&nbsp;=>&nbsp;p.Key);foreach(var&nbsp;key&nbsp;in&nbsp;key_by_value&nbsp;){....}&nbsp;
打开App,查看更多内容
随时随地看视频慕课网APP