c# - Sorting a dictionary by keys in the order in an Arraylist -
I was asked the following question in an interview. I can sort a dictionary from the key, in order that any array is in the list.
For example, I have a dictionary such as
dictionary ; String, string & gt; StringDict = New Dictionary & lt; String, string & gt; (); StringDict.Add ("1", "One"); StringDict.Add ("7", "Seven"); StringDict.Add ("6", "Six"); StringDict.Add ("2", "Two"); StringDict.Add ("3", "Three"); StringDict.Add ("5", "Five"); StringDict.Add ("4", "Four"); and an array list is as follows
array list stringArList = new ArrayList (); stringArList.Add ("1"); StringArList.Add ("2"); stringArList.Add ("3"); StringArList.Add ("5"); stringArList.Add ("6"); StringArList.Add ("7"); stringArList.Add ("4"); How can I sort this array in the order in order?
Well, you can not click a dictionary, but you can Remove the key-value pair as a list and sort the those types: IEnumerable & lt; keyValuePair & lt; String, string & gt; & Gt; Pairs = string dict ordbari (kvp = & gt; string ARLIST.indexoff (kvp.ca)); But there is no way to translate "objects" in any particular order.
You can create a sorted option and a IcpParator < String & gt; var d = new ordered order & lt; String, string & gt; (String Dict, New Position Compaiper (String Elite)); In the form of the implementation Public class status compiler: ICMPier & lt; String & gt; {Private Arrival Keys {Get; Set;} Public Position Comparator (Ariallist Keys) {keys = keys; } Public Intel (String S1, String S2) (Return Keys Indexoff (S1)) Compare. (Compare key (indexoff (s2));}}
Comments
Post a Comment