SortedDictionary和SortedList,sorteddictionary
使用上兩者的接口都類似字典,並且SortedList的比如Find,FindIndex,RemoveAll常用方法都沒提供。
數據結構上二者差異比較大,SortedList查找數據極快,但添加新元素,刪除元素較慢,SortedDictionary查找,添加,刪除速度都比較平均。
博友的測試結果:

直接在Unity3D裡測一下

![]()
public class Test : MonoBehaviour
{
void Start()
{
var sortedDict = new SortedDictionary<string, int>();
sortedDict.Add("a01", 10);
sortedDict.Add("a10", 2);
sortedDict.Add("a03", 5);
sortedDict.Add("a02", 1);
print(sortedDict["a01"]);
foreach (var item in sortedDict)
{
Debug.Log("SortedDictionary: " + item);
}
var sortedList = new SortedList<string, int>();
sortedList.Add("a01", 10);
sortedList.Add("a10", 2);
sortedList.Add("a03", 5);
sortedList.Add("a02", 1);
print(sortedList["a01"]);
foreach (var item in sortedList)
{
Debug.Log("SortedList: " + item);
}
}
}
View Code
調用結果:
