LINQ problem

puffpio

Golden Member
Dec 21, 1999
1,664
0
0
// list of list of KVP's...
List<List<KeyValuePair<string, string>>> source = .................


var output = source.Select( row => row.Find(kvp => kvp.Key =="hello").Value == row.Find(kvp => kvp.Key == "world").Value);

the datatype of output is IEnumerable<bool> instead of IEnumerable<List<KeyValuePair<string,string>>>


any ideas?

 

imported_Dhaval00

Senior member
Jul 23, 2004
573
0
0
It is the correct type. All you're doing is comparing two values and returning the result (true if they are equal, false if not). How are you expecting it to be IEnumerable<List<KeyValuePair<string,string>>> ? Also, supply us with the relevant data information - like what is kvp?

My bad... didn't see that kvp's type was already listed. Apologies for blabbering too early.
 

Rangoric

Senior member
Apr 5, 2006
530
0
71
Originally posted by: Dhaval00
It is the correct type. All you're doing is comparing two values and returning the result (true if they are equal, false if not). How are you expecting it to be IEnumerable<List<KeyValuePair<string,string>>> ? Also, supply us with the relevant data information - like what is kvp?

kvp is KeyValuePair<string,string>
row is List<KeyValuePair<string, string>>

All the info to figure out the issue is there. And you are partially right :)

var output = source.Select( row => row.Find(kvp => kvp.Key =="hello").Value == row.Find(kvp => kvp.Key == "world").Value);

Try Find or FindAll instead of Select. Select takes what you give it and uses the Datasource to execute it. Find gives you results from the datasource. (Find gives the First, FindAll gives all of them)

.Select as an extension method is not the same as select in a normal Linq statement. It confused the buggers outta me the first time too.
 

puffpio

Golden Member
Dec 21, 1999
1,664
0
0
ahh thanks...

i switched the .Select to .Where and we are in business again