本文整理汇总了C#中System.Collections.SortedList.GetKey方法的典型用法代码示例。如果您正苦于以下问题:C# SortedList.GetKey方法的具体用法?C# SortedList.GetKey怎么用?C# SortedList.GetKey使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Collections.SortedList
的用法示例。
在下文中一共展示了SortedList.GetKey方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
//引入命名空间
using System;
using System.Collections;
public class SamplesSortedList {
public static void Main() {
// Creates and initializes a new SortedList.
SortedList mySL = new SortedList();
mySL.Add( 1.3, "fox" );
mySL.Add( 1.4, "jumps" );
mySL.Add( 1.5, "over" );
mySL.Add( 1.2, "brown" );
mySL.Add( 1.1, "quick" );
mySL.Add( 1.0, "The" );
mySL.Add( 1.6, "the" );
mySL.Add( 1.8, "dog" );
mySL.Add( 1.7, "lazy" );
// Gets the key and the value based on the index.
int myIndex=3;
Console.WriteLine( "The key at index {0} is {1}.", myIndex, mySL.GetKey( myIndex ) );
Console.WriteLine( "The value at index {0} is {1}.", myIndex, mySL.GetByIndex( myIndex ) );
// Gets the list of keys and the list of values.
IList myKeyList = mySL.GetKeyList();
IList myValueList = mySL.GetValueList();
// Prints the keys in the first column and the values in the second column.
Console.WriteLine( "\t-KEY-\t-VALUE-" );
for ( int i = 0; i < mySL.Count; i++ )
Console.WriteLine( "\t{0}\t{1}", myKeyList[i], myValueList[i] );
}
}
输出:
The key at index 3 is 1.3. The value at index 3 is fox. -KEY- -VALUE- 1 The 1.1 quick 1.2 brown 1.3 fox 1.4 jumps 1.5 over 1.6 the 1.7 lazy 1.8 dog
示例2: Main
//引入命名空间
using System;
using System.Collections;
class Class1 {
static void Main(string[] args) {
bool ByEmp = false;
SortedList Emps = new SortedList();
Emps.Add("500", "A");
Emps.Add("502", "C");
Emps.Add("501", "B");
Emps.Add("503", "D");
for(int k=0; k<Emps.Count; k++) {
Console.WriteLine("\t{0}\t{1}", Emps.GetKey(k), Emps.GetByIndex(k));
}
}
}