<LINQ(링크)>
데이터 질의 기능
숫자배열로 부터 짝수만을 추출하여 출력
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApp13 { class Program { static void Main(string[] args) { //숫자배열로 부터 짝수만을 추출하여 출력 int[] numbers = { 9, 2, 6, 4, 5, 3, 7, 8, 1, 10 }; var result = from n in numbers where n % 2 == 0 //짝수를 만족하는 조건설정 orderby n //n을 정렬하고 select n; //n을 조회한다. foreach (int n in result) Console.WriteLine($"짝수:{n}"); } } }
'코딩연습 > C#' 카테고리의 다른 글
[C#]람다식(Func대리자) (0) | 2020.06.15 |
---|---|
[C#]LINQ연습문제(레코드조회) (0) | 2020.06.12 |
[C#]대리자의 이벤트 (0) | 2020.06.12 |
[C#]대리자 체인 (0) | 2020.06.12 |
[C#]대리자(delegate) (0) | 2020.06.12 |