的确不方便啊,我找了许多集合类,哈希表,似乎没一个有这种sort方法,真是麻烦啊,难道没的办法啦?

解决方案 »

  1.   

    ARSORT中操作的数组对象在.NET中多用NAMEVALUECOLLECTION,DICTIONARY,HASHTABLE等来表示.
    而.NET中的SORT多是针对KEY,而不是VALUE,所以变通的办法是用KEY来表示VALUE,用VALUE来表示KEY,而逆排序可能需要自己实现ICOMPARER接口来完成.
    .NET 2.0中有很多SORTED的COLLECTION,但好象也没有针对VALUE进行派序的NAMEVALUECOLLECTION.
      

  2.   

    不可能的!
    提供排序函数,却不对值排序。简直是笑话!
    在msdn中搜索一下就应该能够找到当然,满足
    arsort --  对数组进行逆向排序并保持索引关系
    的函数,也是可能没有的。
    不过你完全可以自己写一个.net有php支持环境,你可以安装一个。这样就不用移植php代码了
      

  3.   

    From MSDN(.NET 2.0):SortedList
    Represents a collection of key/value pairs that are sorted by the keys and are accessible by key and by index.
    ---------------------------------------
    //Build the example in MS Visual C# 2005 Expression Edition 
    //
    using System;
    using System.Collections.Generic;
    using System.Text;namespace ConsoleApplication1
    {
        class Program
        {
            static void Main(string[] args)
            {
                System.Collections.SortedList slist = new System.Collections.SortedList();
                slist.Add("d", "a");
                slist.Add("c", "b");
                slist.Add("b", "c");
                slist.Add("a", "d");
                System.Collections.IDictionaryEnumerator iterator=slist.GetEnumerator();
                while (iterator.MoveNext())
                {
                    Console.WriteLine("Key:{0},Value:{1}", iterator.Key.ToString(), iterator.Value.ToString());
                }
                Console.Read();
            }
        }
    }
    Output:
    Key:a,Value:d
    Key:b,Value:c
    Key:c,Value:b
    Key:d,Value:a---------------------------------------------------
    不可能的!
    提供排序函数,却不对值排序。简直是笑话!
    在msdn中搜索一下就应该能够找到to xuzuning(唠叨),好像不是笑话哦!我也不是笑话哦!还有吗?
    SortedDictionaryRepresents a collection of key/value pairs that are sorted on the key.
    微软的笑话还真多^_^
      

  4.   

    楼上的不行吧,
    arsort将数组的值重新排序,由大至小排列
    如果我这样添加
    slist.Add("d", "a");
    slist.Add("c", "c");
    slist.Add("b", "b");
    slist.Add("a", "d");这样结果就不对了啊
      

  5.   

    哦,我没说这是解决方法,
    代码的作用只是告诉我的楼上,"不对VALUE而对NAME排序"那并不是笑话.因为ARSORT保持索引关系不变,意味着是一个NAME-VALUE RELATION也就是说可以认为ARSORT操作的是一个NAME-VALUE COLLECTION,不只是一个INDEXED ARRAY,不幸的是在.NET中
    NAMEVALUECOLLECTION往往按KEY排序而不是ARSORT的VALUE.楼主只看了我的代码,是否看到我第一次的回复?变通的方法是用KEY来表示VALUE,用VALUE来表示KEY,至于查找,一般.NET中的NAMEVALUE COLLECTION都支持双向的查找.但我不敢保证使用VALUE查找的效率.
      

  6.   

    TO Gdj(陈水.智商只有129.非卖品) 
    我觉得PHP提供的很多库函数要比.NET FRAMEWORK还要好:)
      

  7.   

    new System.Collections.ArrayList().Sort();
      

  8.   

    new System.Collections.ArrayList().Reverse();这个可以翻转.