From: |
011netservice@gmail.com |
Date: |
2022-04-22 |
Subject: |
SortedList Class |
SortedList Class
存放(Key和Value均為Object型別)的DictionaryEntry元素清單, 並維持排序. 可同時使用Index或Key存取元素. Index值會隨著Key值變動.
Example
Example: SortedList
using System;
using System.Collections;
public class SamplesSortedList {
public static void Main() {
// Creates and initializes a new SortedList.
SortedList mySL = new SortedList();
mySL.Add("Third", "!");
mySL.Add("Second", "World");
mySL.Add("First", "Hello");
// Displays the properties and values of the SortedList.
Console.WriteLine( "mySL" );
Console.WriteLine( " Count: {0}", mySL.Count );
Console.WriteLine( " Capacity: {0}", mySL.Capacity );
Console.WriteLine( " Keys and Values:" );
PrintKeysAndValues( mySL );
}
public static void PrintKeysAndValues( SortedList myList ) {
Console.WriteLine( "\t-KEY-\t-VALUE-" );
for ( int i = 0; i < myList.Count; i++ ) {
Console.WriteLine( "\t{0}:\t{1}", myList.GetKey(i), myList.GetByIndex(i) );
}
Console.WriteLine();
}
}
/*
This code produces the following output.
mySL
Count: 3
Capacity: 16
Keys and Values:
-KEY- -VALUE-
First: Hello
Second: World
Third: !
*/
Reference:
SortedList
Class
Log:
Date |
Author |
Description |
2017-01-30 |
Honda |
copy from luckstat document. |