C#のStringCollectionの最後に文字列を追加します
StringCollectionの最後に文字列を追加するには、コードは次のとおりです-
例
using System;
using System.Collections.Specialized;
public class Demo {
public static void Main() {
StringCollection strCol = new StringCollection();
strCol.Add("John");
strCol.Add("Tim");
strCol.Add("Gary");
strCol.Add("Katie");
strCol.Add("Andy");
strCol.Add("Amy");
strCol.Add("Scarlett");
strCol.Add("Jacob");
Console.WriteLine("Elements in StringCollection...");
foreach(Object ob in strCol) {
Console.WriteLine(ob);
}
Console.WriteLine("Count of elements = "+strCol.Count);
}
} 出力
これにより、次の出力が生成されます-
Elements in StringCollection... John Tim Gary Katie Andy Amy Scarlett Jacob Count of elements = 8
例
別の例を見てみましょう-
using System;
using System.Collections.Specialized;
public class Demo {
public static void Main() {
StringCollection strCol = new StringCollection();
strCol.Add("One");
strCol.Add("Two");
strCol.Add("Three");
strCol.Add("Four");
strCol.Add("Five");
Console.WriteLine("Elements in StringCollection...");
foreach(Object ob in strCol) {
Console.WriteLine(ob);
}
}
} 出力
これにより、次の出力が生成されます-
Elements in StringCollection... One Two Three Four Five
-
C#のSortedListクラスとは何ですか?
ソートされたリストは、配列とハッシュテーブルの組み合わせです。キーまたはインデックスを使用してアクセスできるアイテムのリストが含まれています。インデックスを使用してアイテムにアクセスする場合、それはArrayListであり、キーを使用してアイテムにアクセスする場合、それはハッシュテーブルです。アイテムのコレクションは常にキー値で並べ替えられます。 SortedList-に4つのキーと値のペアを追加した例を見てみましょう。 例 using System; using System.Collections; namespace Demo { class Program
-
2つのリストを比較し、C#の3番目のリストに違いを追加するにはどうすればよいですか?
まず、2つのリストを設定します- リスト1 List < string > list1 = new List < string > (); list1.Add("A"); list1.Add("B"); list1.Add("C"); list1.Add("D"); リスト2 List < string > list2 = new List < string > (); list2.Add("C"); list2.Add("D"