C#のHybridDictionaryの値を含むICollectionを取得します
HybridDictionaryの値を含むICollectionを取得するには、コードは次のとおりです-
例
using System;
using System.Collections.Specialized;
public class Demo {
public static void Main(){
HybridDictionary dict = new HybridDictionary();
dict.Add("One", "Katie");
dict.Add("Two", "Andy");
dict.Add("Three", "Gary");
dict.Add("Four", "Mark");
dict.Add("Five", "Marie");
dict.Add("Six", "Sam");
dict.Add("Seven", "Harry");
dict.Add("Eight", "Kevin");
dict.Add("Nine", "Ryan");
String[] strArr = new String[dict.Count];
dict.Values.CopyTo(strArr, 0);
for (int i = 0; i < dict.Count; i++)
Console.WriteLine(strArr[i]);
}
} 出力
これにより、次の出力が生成されます-
Kevin Harry Mark Gary Katie Marie Sam Andy Ryan
例
別の例を見てみましょう-
using System;
using System.Collections.Specialized;
public class Demo {
public static void Main() {
HybridDictionary dict = new HybridDictionary();
dict.Add("1", "A");
dict.Add("2", "B");
dict.Add("3", "C");
dict.Add("4", "D");
dict.Add("5", "E");
dict.Add("6", "F");
String[] strArr = new String[dict.Count];
dict.Values.CopyTo(strArr, 0);
for (int i = 0; i < dict.Count; i++)
Console.WriteLine(strArr[i]);
}
} 出力
これにより、次の出力が生成されます*マイナス'
A B C D E F
-
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("
-
C#リストの要素の範囲を取得する
GetRange()メソッドを使用して、要素の範囲を取得します- まず、リストを設定して要素を追加します- List<int> arr1 = new List<int>(); arr1.Add(10); arr1.Add(20); arr1.Add(30); arr1.Add(40); arr1.Add(50); ここで、新しいリストの下で、インデックス1と3の間の要素の範囲を取得します- List<int> myList = arr1.GetRange(1, 3); これが完全なコードです- 例 using System; using System.