C#のListDictionaryの値を含むICollectionを取得します
ListDictionaryの値を含むICollectionを取得するには、コードは次のとおりです-
例
using System;
using System.Collections;
using System.Collections.Specialized;
public class Demo {
public static void Main(){
ListDictionary listDict = new ListDictionary();
listDict.Add("1", "Laptop");
listDict.Add("2", "Tablet");
listDict.Add("3", "Desktop");
listDict.Add("4", "Speaker");
listDict.Add("5", "Earphone");
listDict.Add("6", "Headphone");
ICollection col = listDict.Values;
foreach(String s in col){
Console.WriteLine(s);
}
}
} 出力
これにより、次の出力が生成されます-
Laptop Tablet Desktop Speaker Earphone Headphone
例
別の例を見てみましょう-
using System;
using System.Collections;
using System.Collections.Specialized;
public class Demo {
public static void Main(){
ListDictionary listDict = new ListDictionary();
listDict.Add("A", "Tom");
listDict.Add("B", "John");
listDict.Add("C", "Kevin");
listDict.Add("D", "Tim");
ICollection col = listDict.Values;
foreach(String s in col){
Console.WriteLine(s);
}
}
} 出力
これにより、次の出力が生成されます-
Tom John Kevin Tim
-
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.