'Retrieve value from a sorted dictionary with the help of ke in C#

I have a Dictionary, which has a hash table, that is, keys are not sorted.

Conflicts oConflicts = oClash.Conflicts;
Dictionary<string, string> dConflicts = new Dictionary<string, string>();
Conflict oConflict;  
for (int iLoopC = 1; iLoopC <= oConflicts.Count; iLoopC++)
{
    oConflict = oConflicts.Item(iLoopC);
    if (Math.Abs(oConflict.Value) < 3)
    {
       dConflicts.Add(oConflict.Value.ToString(), oConflict.SecondProduct.ToString());                            
    }
}

I have sorted the dictionary by LINQ:

var sortedDict = dConflicts.OrderBy(x => x.Value).ToDictionary(x => x.Key, x => x.Value);

I am new to this. Could someone help me with how to get the value stored in sortedDict using the particular key value? Like the last value using count the array elements.



Solution 1:[1]

This seems that you are only using a Dictionary just to be sure not Adding duplicates, pretty overkill, but hey...

var searchedLastElement = dConflicts.OrderBy(x => x.Value).LastOrDefault().Value;

yod didn't need the sorted list to be cast again to dictionary only to retrieve the last element

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 J.Salas