我有一个场景,我可以使用NameValueCollection或IDictionary.但我想知道哪一个会更好地表现.
- 使用NameValueCollection
NameValueCollection options()
{
NameValueCollection nc = new NameValueCollection();
nc = ....; //populate nc here
if(sorting)
//sort NameValueCollection nc here
return nc;
}
Run Code Online (Sandbox Code Playgroud)
- 使用IDictionary
IDictionary<string, string> options()
{
Dictionary<string, string> optionDictionary = new Dictionary<string, string>();
optionDictionary = ....; //populate
if(sorting)
return new SortedDictionary<string, string>(optionDictionary);
else
return optionDictionary;
}
Run Code Online (Sandbox Code Playgroud) Dictionary<string, string> optionDictionary = new Dictionary<string, string>();
optionDictionary = ....;
SortedDictionary<string, string> optionsSorted;
if(sorting)
{
optionsSorted = new SortedDictionary<string, string>(optionDictionary );
// Convert SortedDictionary into Dictionary
}
return optionDictionary ;
Run Code Online (Sandbox Code Playgroud) 我写了下面的代码,它也有效 - 但我想知道它们是否比这更好:
NameValueCollection optionInfoList = ..... ;
if (aSorting)
{
optionInfoListSorted = new nameValueCollection();
String[] sortedKeys = optionInfoList.AllKeys;
Array.Sort(sortedKeys);
foreach (String key in sortedKeys)
optionInfoListSorted.Add(key, optionInfoList[key]);
return optionInfoListSorted;
}
Run Code Online (Sandbox Code Playgroud) 我有一个要求,需要我将用户重定向到他浏览历史记录的上一页.我正在使用ASP.net MVC 1.0.我不想用javascript来实现这一点.有什么指针吗?