I have dictionary Dictionary<int, List<string>> taskList = new Dictionary<int, List<string>>();
which gives me the out like:
Task ID: 1664003 Values:
"2"
"5"
"1"
"4"
"3"
Task ID: 1664004 Values:
"1"
"2"
"3"
"5"
"4"
Task ID: 1664005 Values:
"1"
"2"
"5"
"4"
"3"
Now I want to search for keys of zero index of pair value like below:
Values: "2" Task Id: 1664003
Value: "1" Task Id: 1664004, 1664005
I want to achieve it using lambda expression
3
Answers
You’ll need to iterate over every entry of the dictionary, get the first item of the list and compare it to what you’re looking for, like so:
P.S You might want to rethink your data structure, as this seems like a misuse of a dictionary
Output:
Your dictionary is the wrong way round for this kind of search. Consider creating a dictionary that is the right way round, then search it many times
Ideally you can keep your
dRev
for as long as is reasonably practical; if you have a lot of searches to do in a batch, then rebuilding it makes sense. There’s no point rebuilding it every time you search for a single item, but perhaps consider taking the thing that builds the dictionary you have right now and adding to it so it builds a reverse dictionary too, if you’re going to be searching in this direction often, but for a single item at a time.If your searches are only ever in this direction, your dictionary may be the wrong way round entirely and the thing that maintains it should be reworked to reverse it permanently