在 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
廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP