作者taicomjp (御神者)
看板C_Sharp
标题Re: [问题] 是否可用字串索引
时间Fri Apr 15 16:30:35 2005
SortedList好像会按照字母排序
也因为这样Sorted好像会执行比较慢
有没有办法将先插入的索引就是0
第二个插入的就1,以此类推
而不会自动帮你排序...
: using System;
: using System.Collections;
: public class SamplesSortedList {
: public static void Main() {
: // Creates and initializes a new SortedList.
: SortedList mySL = new SortedList();
: mySL.Add("First", "Hello");
: mySL.Add("Second", "World");
: mySL.Add("Third", "!");
: // 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();
: }
: }
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 61.62.240.26
1F:推 virdust2003:arraylist 140.113.164.7 04/16