C#のOrderedDictionaryでIDictionaryEnumeratorオブジェクトを取得します
OrderedDictionaryでIDictionaryEnumeratorオブジェクトを取得するには、コードは次のとおりです-
例
using System;
using System.Collections;
using System.Collections.Specialized;
public class Demo {
public static void Main() {
OrderedDictionary dict = new OrderedDictionary();
dict.Add("1", "One");
dict.Add("2", "Two");
dict.Add("3", "Three");
dict.Add("4", "Four");
dict.Add("5", "Five");
dict.Add("6", "Six");
dict.Add("7", "Seven");
dict.Add("8", "Eight");
IDictionaryEnumerator demoEnum = dict.GetEnumerator();
while (demoEnum.MoveNext()) {
Console.WriteLine("Key = " + demoEnum.Key + ", Value = " + demoEnum.Value);
}
}
} 出力
これにより、次の出力が生成されます-
Key = 1, Value = One Key = 2, Value = Two Key = 3, Value = Three Key = 4, Value = Four Key = 5, Value = Five Key = 6, Value = Six Key = 7, Value = Seven Key = 8, Value = Eight
例
別の例を見てみましょう-
using System;
using System.Collections;
using System.Collections.Specialized;
public class Demo {
public static void Main() {
OrderedDictionary dict = new OrderedDictionary();
dict.Add("1", "Appliances");
dict.Add("2", "Supplies");
dict.Add("3", "Electronics");
dict.Add("4", "Clothing");
dict.Add("5", "Books");
dict.Add("6", "Accessories"); ;
IDictionaryEnumerator demoEnum = dict.GetEnumerator();
while (demoEnum.MoveNext()) {
Console.WriteLine("Key = " + demoEnum.Key + ", Value = " + demoEnum.Value);
}
}
} 出力
これにより、次の出力が生成されます-
Key = 1, Value = Appliances Key = 2, Value = Supplies Key = 3, Value = Electronics Key = 4, Value = Clothing Key = 5, Value = Books Key = 6, Value = Accessories
-
C#のOrderedDictionaryの値を含むICollectionを取得します
OrderedDictionaryの値を含むICollectionを取得するには、コードは次のとおりです- 例 using System; using System.Collections; using System.Collections.Specialized; public class Demo { public static void Main(){ OrderedDictionary dict = new OrderedDictionary(); dict.Add("
-
JavaScriptでオブジェクトの値を取得するにはどうすればよいですか?
Object.values()などのメソッドがいくつかあります オブジェクトの値を取得します。しかし、これらの方法では、値を見つけるプロセスに時間がかかります。これを軽減するには、 Underscore.js javascriptのライブラリは、 _。values()と呼ばれるメソッドを提供しています 。このメソッドでは、値を実行するためにforループは必要ありません。これは、オブジェクトの値を実行するための直接的な方法です。 次の例では、オブジェクトの値は Object.values()を使用して実行されました。 方法。このメソッドにはforループが必要です 値を実行します。 例 &l