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. 微软的笑话还真多^_^
而.NET中的SORT多是针对KEY,而不是VALUE,所以变通的办法是用KEY来表示VALUE,用VALUE来表示KEY,而逆排序可能需要自己实现ICOMPARER接口来完成.
.NET 2.0中有很多SORTED的COLLECTION,但好象也没有针对VALUE进行派序的NAMEVALUECOLLECTION.
提供排序函数,却不对值排序。简直是笑话!
在msdn中搜索一下就应该能够找到当然,满足
arsort -- 对数组进行逆向排序并保持索引关系
的函数,也是可能没有的。
不过你完全可以自己写一个.net有php支持环境,你可以安装一个。这样就不用移植php代码了
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.
微软的笑话还真多^_^
arsort将数组的值重新排序,由大至小排列
如果我这样添加
slist.Add("d", "a");
slist.Add("c", "c");
slist.Add("b", "b");
slist.Add("a", "d");这样结果就不对了啊
代码的作用只是告诉我的楼上,"不对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查找的效率.
我觉得PHP提供的很多库函数要比.NET FRAMEWORK还要好:)