本文整理汇总了C#中System.Collections.SortedList.GetKeyList方法的典型用法代码示例。如果您正苦于以下问题:C# SortedList.GetKeyList方法的具体用法?C# SortedList.GetKeyList怎么用?C# SortedList.GetKeyList使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Collections.SortedList
的用法示例。
在下文中一共展示了SortedList.GetKeyList方法的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 MainClass
{
public static void Main()
{
SortedList mySortedList = new SortedList();
mySortedList.Add("NY", "New York");
mySortedList.Add("FL", "Florida");
mySortedList.Add("AL", "Alabama");
mySortedList.Add("WY", "Wyoming");
mySortedList.Add("CA", "California");
foreach (string myKey in mySortedList.Keys)
{
Console.WriteLine("myKey = " + myKey);
}
foreach(string myValue in mySortedList.Values)
{
Console.WriteLine("myValue = " + myValue);
}
Console.WriteLine("Getting the key list");
IList myKeyList = mySortedList.GetKeyList();
foreach(string myKey in myKeyList)
{
Console.WriteLine("myKey = " + myKey);
}
}
}