I am trying to combine two SortedDictionaries
, change the result to a List<KeyvaluePair<string,string>>
and Sort()
the result. The following statement throws an error:
var combinedEntries = from p in leftDict.Union(rightDict).ToList().Sort(myComparer) select p;
Error: Could not find an implementation of the query pattern for source type 'void'. 'Select' not found.
This is not working because Sort() returns void. If I split up the statement, it works:
var combinedEntries = from p in leftDict.Union(rightDict) select p;
List<KeyValuePair<string, string>> finalentries = combinedEntries.ToList();
finalentries.Sort(comparer);
I understand that sort is a method of List type and not IEnumerable
, but I thought calling ToList()
before Sort()
will take care of that problem. So first question is can it be used like I am trying in the first statement? If not, how do I make use of orderby
here?