목록 설정 -
List<int> myList = new List<int>() {
5,
10,
17,
19,
23,
33
}; 2로 나눌 수 있는 요소를 찾아야 한다고 가정해 보겠습니다. 이를 위해 Find() 메서드를 사용하십시오 -
int val = myList.Find(item => item % 2 == 0);
다음은 전체 코드입니다 -
예시
using System;
using System.Collections.Generic;
using System.Linq;
class Demo {
static void Main() {
List<int> myList = new List<int>() {
5,
10,
17,
19,
23,
33
};
Console.WriteLine("List: ");
foreach(int i in myList) {
Console.WriteLine(i);
}
int val = myList.Find(item => item % 2 == 0);
Console.WriteLine("Element that divides by zero: "+val);
}
} 출력
List: 5 10 17 19 23 33 Element that divides by zero: 10