목록 모음의 예를 살펴보겠습니다.
우리는 요소를 설정했습니다 -
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);
}
}