在C#中获取ArrayList中一系列元素的枚举数
要获得ArrayList中一系列元素的枚举数,代码如下-
示例
using System;
using System.Collections;
public class Demo {
public static void Main(){
ArrayList arrList = new ArrayList();
arrList.Add(100);
arrList.Add(200);
arrList.Add(300);
arrList.Add(400);
arrList.Add(500);
Console.WriteLine("Display elements in a range...");
IEnumerator demoEnum = arrList.GetEnumerator(1, 3);
while (demoEnum.MoveNext()) {
Object ob = demoEnum.Current;
Console.WriteLine(ob);
}
}
}输出结果
这将产生以下输出-
Display elements in a range... 200 300 400
示例
现在让我们来看另一个示例-
using System;
using System.Collections;
public class Demo {
public static void Main(){
ArrayList arrList = new ArrayList();
arrList.Add("Andy");
arrList.Add("Katie");
arrList.Add("Taylor");
arrList.Add("Steve");
arrList.Add("Nathan");
arrList.Add("Carl");
arrList.Add("Mark");
arrList.Add("Amy");
arrList.Add("Jacob");
arrList.Add("John");
Console.WriteLine("Display elements in a range...");
IEnumerator demoEnum = arrList.GetEnumerator(1, 3);
while (demoEnum.MoveNext()) {
Object ob = demoEnum.Current;
Console.WriteLine(ob);
}
Console.WriteLine("Display elements in a range...");
demoEnum = arrList.GetEnumerator(3, 5);
while (demoEnum.MoveNext()) {
Object ob = demoEnum.Current;
Console.WriteLine(ob);
}
}
}输出结果
这将产生以下输出-
Display elements in a range... Katie Taylor Steve Display elements in a range... Steve Nathan Carl Mark Amy
热门推荐
10 小红书平安祝福语简短
11 生日祝福语大全女孩简短
12 收生日红包祝福语 简短
13 领证幽默祝福语简短
14 法考面试祝福语简短
15 老哥出门祝福语简短语
16 送灯祝福语简短独特
17 幼儿狗年祝福语大全简短
18 好听的元旦简短祝福语