在C#中获取StringCollection中的字符串数
要获取StringCollection中的字符串数,代码如下-
示例
using System;
using System.Collections.Specialized;
public class Demo {
public static void Main() {
StringCollection strCol = new StringCollection();
String[] strArr = new String[] { "A", "B", "C", "D", "E", "F", "G", "H" };
Console.WriteLine("StringCollection elements...");
foreach (string str in strArr) {
Console.WriteLine(str);
}
strCol.AddRange(strArr);
Console.WriteLine("Element at 5th index = "+strCol[5]);
Console.WriteLine("Count of strings in StringCollection = " + strCol.Count);
}
}输出结果
这将产生以下输出-
StringCollection elements... A B C D E F G H Element at 5th index = F Count of strings in StringCollection = 8
示例
让我们看另一个例子-
using System;
using System.Collections.Specialized;
public class Demo {
public static void Main() {
StringCollection strCol = new StringCollection();
String[] strArr = new String[] { "10", "20", "30", "40", "50" };
Console.WriteLine("StringCollection elements...");
foreach (string str in strArr) {
Console.WriteLine(str);
}
strCol.AddRange(strArr);
Console.WriteLine("Count of strings in StringCollection = " + strCol.Count);
}
}输出结果
这将产生以下输出-
StringCollection elements... 10 20 30 40 50 Count of strings in StringCollection = 5
热门推荐
10 对学姐的简短祝福语
11 朋友节最简短祝福语
12 学生祝福语简短古诗句
13 开业经典祝福语简短
14 妈妈生日贺卡祝福语 简短
15 朋友弟弟生日祝福语简短
16 18岁的祝福语简短
17 对睡觉的祝福语简短
18 圣诞简短祝福语给父母