【发布时间】:2014-06-08 23:11:25
【问题描述】:
我在一次采访中被问到以下问题。如何按数组列表中的顺序对字典进行排序。
所以例如我有一个字典如下
Dictionary<string, string> stringDict = new Dictionary<string, string>();
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");
还有一个数组列表如下
ArrayList stringArList = new ArrayList();
stringArList.Add("1");
stringArList.Add("2");
stringArList.Add("3");
stringArList.Add("5");
stringArList.Add("6");
stringArList.Add("7");
stringArList.Add("4");
如何按照数组列表中的顺序对字典进行排序?
【问题讨论】:
-
嗯。我的回答是“字典没有订单”。如果他们因此不雇用我,我就会知道无论如何我都不想为他们工作。 :)
-
...除非它是有序字典。
-
我同意 D Stanley 的观点——这很可能是一个技巧问题。在我看来,这些面试问题真的已经过时了,需要用老式的“你能解决这个有效的问题吗?你会怎么做”编码时间来代替。像这样的问题是由有点高级的工程师提出来提高他们自己的自尊心的。 (我知道,因为我创造了很多……然后我意识到我不需要通过采访来提高我的自尊心……我真的很擅长我所做的事情,我的行为证明了证明我比我正在采访的人更聪明。)
-
“像这样的问题是由有点高级的工程师为了提高自己的自尊而创造的”我完全同意......
-
今天早上早些时候提出了这个确切的问题。但是无法找到它。我以为@DStanley 确实回答了它
标签: c# dictionary arraylist