在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
热门推荐
10 高温祝福语短语大全简短
11 炸鸡拼盘生日祝福语简短
12 老板辞职后祝福语简短
13 同学有弟弟祝福语简短
14 开店送礼祝福语大全简短
15 生日祝福语贺卡文字简短
16 元旦的祝福语简短 公司
17 老哥出门祝福语简短语
18 英文祝福语简短带名字