小编Ujw*_*ire的帖子

IDictionary <string,string>或NameValueCollection

我有一个场景,我可以使用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)

c# generics

31
推荐指数
3
解决办法
1万
查看次数

如何将sortedDictionary转换为字典?

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)

c# generics

6
推荐指数
2
解决办法
6875
查看次数

如何使用C#中的键对NameValueCollection进行排序?

我写了下面的代码,它也有效 - 但我想知道它们是否比这更好:

 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)

c# sorting collections

5
推荐指数
1
解决办法
5727
查看次数

使用ASP.net MVC的后退按钮功能

我有一个要求,需要我将用户重定向到他浏览历史记录的上一页.我正在使用ASP.net MVC 1.0.我不想用javascript来实现这一点.有什么指针吗?

asp.net-mvc

4
推荐指数
2
解决办法
9704
查看次数

标签 统计

c# ×3

generics ×2

asp.net-mvc ×1

collections ×1

sorting ×1