C#でSortedDictionaryを反復処理する列挙子を取得します
SortedDictionaryを反復処理する列挙子を取得するには、コードは次のとおりです-
例
using System;
using System.Collections;
using System.Collections.Generic;
public class Demo {
public static void Main(){
SortedDictionary<int, string>sortedDict = new SortedDictionary<int, string>();
sortedDict.Add(100, "Mobile");
sortedDict.Add(200, "Laptop");
sortedDict.Add(300, "Desktop");
sortedDict.Add(400, "Speakers");
sortedDict.Add(500, "Headphone");
sortedDict.Add(600, "Earphone");
Console.WriteLine("SortedDictionary key-value pairs...");
IDictionaryEnumerator demoEnum = sortedDict.GetEnumerator();
while (demoEnum.MoveNext())
Console.WriteLine("Key = " + demoEnum.Key + ", Value = " + demoEnum.Value);
}
} 出力
これにより、次の出力が生成されます-
SortedDictionary key-value pairs... Key = 100, Value = Mobile Key = 200, Value = Laptop Key = 300, Value = Desktop Key = 400, Value = Speakers Key = 500, Value = Headphone Key = 600, Value = Earphone
例
別の例を見てみましょう-
using System;
using System.Collections;
using System.Collections.Generic;
public class Demo {
public static void Main(){
SortedDictionary<int, int> sortedDict = new SortedDictionary<int, int>();
sortedDict.Add(100, 1);
sortedDict.Add(200, 2);
sortedDict.Add(300, 3);
sortedDict.Add(400, 4);
sortedDict.Add(500, 5);
sortedDict.Add(600, 6);
sortedDict.Add(700, 7);
sortedDict.Add(800, 8);
sortedDict.Add(900, 9);
sortedDict.Add(1000, 10);
Console.WriteLine("SortedDictionary key-value pairs...");
IDictionaryEnumerator demoEnum = sortedDict.GetEnumerator();
while (demoEnum.MoveNext())
Console.WriteLine("Key = " + demoEnum.Key + ", Value = " + demoEnum.Value);
}
} 出力
これにより、次の出力が生成されます-
SortedDictionary key-value pairs... Key = 100, Value = 1 Key = 200, Value = 2 Key = 300, Value = 3 Key = 400, Value = 4 Key = 500, Value = 5 Key = 600, Value = 6 Key = 700, Value = 7 Key = 800, Value = 8 Key = 900, Value = 9 Key = 1000, Value = 10
-
C#でStringCollectionを反復処理する列挙子を取得します
StringCollectionを反復処理する列挙子を取得するには、コードは次のとおりです- 例 using System; using System.Collections.Specialized; public class Demo { public static void Main(){ StringCollection stringCol = new StringCollection(); String[] arr = new String[] { "100"
-
C#でドライブ形式を取得する
DriveFormatプロパティを使用して、C#でドライブ形式を取得します。 フォーマットを表示するドライブを設定します- DriveInfo dInfo = new DriveInfo("C"); 次に、DriveFormatを使用してドライブフォーマットを取得します- dInfo.DriveFormat Windowsシステムのドライブ形式は、NTFSまたはFAT32です。 これが完全なコードです- 例 using System; using System.Linq; using System.IO; public class Demo { &nb