从C#中的集合中检索元素
让我们看一个列表集合的例子。
我们已经设置了元素-
List<int> list = new List<int>(); list.Add(20); list.Add(40); list.Add(60); list.Add(80);
现在,我们需要从列表中检索第一个元素。为此,像这样设置索引-
int a = list[0];
以下是显示如何从列表集合中检索元素的示例-
示例
using System;
using System.Collections.Generic;
class Demo {
static void Main(String[] args) {
List<int> list = new List<int>();
list.Add(20);
list.Add(40);
list.Add(60);
list.Add(80);
foreach (int val in list) {
Console.WriteLine(val);
}
int a = list[0];
Console.WriteLine("First element: "+a);
}
}热门推荐
6 带清的简短祝福语
10 城市祝福语简短10字
11 生日祝福语大全女孩简短
12 低调祝福语简短10字
13 红颜生日祝福语简短独特
14 传统新年祝福语大全 简短
15 祝老婆生日祝福语简短
16 高考祝福语简短10字
17 八十大寿简短祝福语
18 鼓掌祝福语简短10字