C# System.Collections.SortedList

 1 using System;
 2 using System.Collections;
 3 public class SamplesSortedList  {
 4 
 5    public static void Main()  {
 6 
 7       // Creates and initializes a new SortedList.
 8       SortedList mySL = new SortedList();
 9        mySL.Add("Third", "!");
10        mySL.Add("Second", "World");
11        mySL.Add("First", "Hello");
12 
13       // Displays the properties and values of the SortedList.
14       Console.WriteLine( "mySL" );
15       Console.WriteLine( "  Count:    {0}", mySL.Count );
16       Console.WriteLine( "  Capacity: {0}", mySL.Capacity );
17       Console.WriteLine( "  Keys and Values:" );
18       PrintKeysAndValues( mySL );
19    }
20 
21 
22    public static void PrintKeysAndValues( SortedList myList )  {
23       Console.WriteLine( "\t-KEY-\t-VALUE-" );
24       for ( int i = 0; i < myList.Count; i++ )  {
25          Console.WriteLine( "\t{0}:\t{1}", myList.GetKey(i), myList.GetByIndex(i) );
26       }
27       Console.WriteLine();
28    }
29 }
30 /*
31 This code produces the following output.
32 
33 mySL
34   Count:    3
35   Capacity: 16
36   Keys and Values:
37     -KEY-    -VALUE-
38     First:    Hello
39     Second:    World
40     Third:    !
41 */

 

构造函数 

SortedList()

初始化 SortedList 类的新实例,该实例为空、具有默认初始容量并根据 IComparable接口(此接口由添加到 SortedList 对象中的每个键实现)进行排序。

SortedList(IComparer)

初始化 SortedList 类的新实例,该实例为空、具有默认初始容量并根据指定的 IComparer 接口进行排序。

SortedList(IComparer, Int32)

初始化 SortedList 类的新实例,该实例为空、具有指定的初始容量并根据指定的 IComparer 接口排序。

SortedList(IDictionary)

初始化 SortedList 类的新实例,该实例包含从指定字典复制的元素、具有与所复制的元素数相同的初始容量并根据由每个键实现的 IComparable 接口排序。

SortedList(IDictionary, IComparer)

初始化 SortedList 类的新实例,该实例包含从指定字典复制的元素、具有与所复制的元素数相同的初始容量并根据指定的 IComparer 接口排序。

SortedList(Int32)

初始化 SortedList 类的新实例,该实例为空、具有指定的初始容量并且根据 IComparable 接口(此接口由添加到 SortedList 对象的每个键实现)进行排序。

属性 

Capacity

获取或设置 SortedList 对象的容量。

Count

获取 SortedList 对象中包含的元素数。

IsFixedSize

获取一个值,该值指示 SortedList 对象是否具有固定大小。

IsReadOnly

获取一个值,该值指示 SortedList 对象是否为只读。

IsSynchronized

获取一个值,该值指示对 SortedList 对象的访问是否同步(线程安全)。

Item[Object]

获取或设置与 SortedList 对象中的特定键相关联的值。

Keys

获取 SortedList 对象中的键。

SyncRoot

获取一个对象,该对象可用于同步对 SortedList 对象的访问。

Values

获取 SortedList 对象中的值。

方法 

Add(Object, Object)

将带有指定键和值的元素添加到 SortedList 对象。

Clear()

从 SortedList 对象中移除所有元素。

Clone()

创建 SortedList 对象的浅表副本。

Contains(Object)

确定 SortedList 对象是否包含特定键。

ContainsKey(Object)

确定 SortedList 对象是否包含特定键。

ContainsValue(Object)

确定 SortedList 对象是否包含特定值。

CopyTo(Array, Int32)

从指定数组索引开始将 SortedList 元素复制到一维 Array 对象中。

Equals(Object)

确定指定的对象是否等于当前对象。

(Inherited from Object)
GetByIndex(Int32)

获取 SortedList 对象的指定索引处的值。

GetEnumerator()

返回一个循环访问 IDictionaryEnumerator 对象的 SortedList 对象。

GetHashCode()

作为默认哈希函数。

(Inherited from Object)
GetKey(Int32)

获取 SortedList 对象的指定索引处的键。

GetKeyList()

获取 SortedList 对象中的键。

GetType()

获取当前实例的 Type

(Inherited from Object)
GetValueList()

获取 SortedList 对象中的值。

IndexOfKey(Object)

返回 SortedList 对象中指定键的从零开始的索引。

IndexOfValue(Object)

返回指定的值在 SortedList 对象中第一个匹配项的从零开始的索引。

MemberwiseClone()

创建当前 Object 的浅表副本。

(Inherited from Object)
Remove(Object)

从 SortedList 对象中移除带有指定键的元素。

RemoveAt(Int32)

移除 SortedList 对象的指定索引处的元素。

SetByIndex(Int32, Object)

替换 SortedList 对象中指定索引处的值。

Synchronized(SortedList)

返回 SortedList 对象的同步(线程安全)包装。

ToString()

返回表示当前对象的字符串。

(Inherited from Object)
TrimToSize()

将容量设置为 SortedList 对象中元素的实际数目。

posted on 2019-03-25 12:10  帅胡  阅读(770)  评论(0编辑  收藏  举报

导航