C# LINQ
![[C#] Fluent vs Query (LINQ Fluent vs Query Syntax)](https://img1.daumcdn.net/thumb/R750x0/?scode=mtistory2&fname=https%3A%2F%2Fblog.kakaocdn.net%2Fdn%2FciVb3x%2FbtqD0hWyMgD%2FxT18mvwKJGlnKnDlRuXUBK%2Fimg.png)
[C#] Fluent vs Query (LINQ Fluent vs Query Syntax)
1. 핵심 정리 using System; using System.Collections.Generic; using System.Linq; class Program { static void Main() { string[] arr = {"kim", "shin", "lee", "park", "choi"}; // Fluent Syntax var e = arr.Where(s => s.Contains("i")) .OrderBy(s => s.Length) .Select(s => s.ToUpper()); foreach(var n in e) Console.WriteLine(n); } } 문자열이 5개 들어있는 배열이 있다. 해당 배열에서 LINQ를 이용해서 필터링 후 요소를 꺼내보려고 한다. 먼저 Where을 통해 문자열..
![[C#] LINQ 원리](https://img1.daumcdn.net/thumb/R750x0/?scode=mtistory2&fname=https%3A%2F%2Fblog.kakaocdn.net%2Fdn%2FnGVT6%2FbtqDXEk0xyy%2FY2kkQqc3a4vWrBeSVSJJx1%2Fimg.png)
[C#] LINQ 원리
1. 핵심 정리 using System; using System.Collections.Generic; using System.Linq; class Program { static void Main() { int[] arr = {1, 2, 3, 4, 5}; IEnumerable e = arr.Select(n => n * 10); arr[0] = 0; foreach(int n in e) Console.WriteLine(n); } } 1부터 5까지 5개의 요소가 들어있는 배열이 있다. 그리고 query method를 이용하여 요소마다 * 10을 한 값을 출력하려고 한다. 이 때, 배열의 0번째 요소에 0을 넣고 출력한다면 결과가 어떻게 나올까? 어차피 열거자로 뽑은 이후에 0을 넣은것이니 그대로 10, 20, ..
![[C#] LINQ 개념 (Language INtegrated Query)](https://img1.daumcdn.net/thumb/R750x0/?scode=mtistory2&fname=https%3A%2F%2Fblog.kakaocdn.net%2Fdn%2FbPauHK%2FbtqDXE5D1OQ%2FZDv9kOf58u1RbCuamCPw00%2Fimg.png)
[C#] LINQ 개념 (Language INtegrated Query)
1. 사전 복습 using System; using System.Collections.Generic; class Program { static void Main() { int[] arr = {1, 2, 3, 4, 5}; foreach(int n in arr) Console.WriteLine(n) IEnumerable col = arr; foreach(int n in col) Console.WriteLine(n); } } 배열을 하나 만들고 foreach를 이용해 요소를 출력해보는 코드이다. 그런데 foreach의 원리는 결국 배열이 갖고있는 GetEnumerator() 메소드를 호출해 열거자를 꺼내는 방식이였다. 모든 컬렉션은 IEnumerable 인터페이스를 구현해야 하고 배열도 컬렉션이므로 GetEn..