c# - linq getting key from list keyvalue pair -


this seems simple, have list of keyvalue pairs , linq statement trying the key, dont understand why dosent work ex

   list<keyvaluepair<int, string>> list = new list<keyvaluepair<int, string>>(); 

list contains values: 1, test1 | 2, test2 | 3, test3 data linq statement is:

string key = list.asenumerable(x => x.value == "test2").select(x => x.key).tostring(); 

seems simple enough work dosent?

to single value's key, you'd do:

string key = list.single(x => x.value == "test2").key.tostring(); 

what you've written should not compile. asenumerable() not have overload taking predicate.

if did compile, not give intended you're calling tostring() on ienumerable<int>, return type's name , not single() value or first() value in enumeration.


Comments

Popular posts from this blog

php - SPIP: From Tag directly to an article -

jquery - isAjaxRequest always return false -

ruby on rails - In a controller spec, how to find a specific tag in the generated view? -