Tuesday, 15 June 2010

c# - extract information from a dictionary -



c# - extract information from a dictionary -

i have dictionary keys product codes , values below each keys specifics of products (e.g. weight, colour, price, etc.). let's code loops through list of product codes have. want check code (called mykey in code below) in dictionary, in case want extract properties (let's colour , cost in case). trying next without success:

var mycolour = mydictionary .where(x => mydictionary.keys.contains(mykey)) .select(x => x.value.colour); var myprice = mydictionary .where(x => mydictionary.keys.contains(mykey)) .select(x => x.value.price);

i don't have error, don't see results stored in variables mycolor , myprice.

what right syntax problem?

you seem on complicating things. next should want.

if (mydictionary.containskey(mykey)) { var thevalue = mydictionary[mykey].someproperty }

c# linq dictionary

No comments:

Post a Comment