티스토리 뷰
LINQ 마지막 강의 입니다.
고생하셨습니다~
1. Conversion operators
- LINQ Result =} IEnumerable{T}
- ToArray()
var doublesArray = sortedDoubles.ToArray();
- * ToList()
var wordList = sortedWords.ToList();
- ToDictionary()
var scoreRecordsDict = scoreRecords.ToDictionary(sr =} sr.Name);
- * OfType{T}()
var doubles = numbers.OfType{double}();
2. Element operators
- First()
(from p in products where p.ProductID == 12 select p) .First();
.Single() ?
- * FirstOrDefault()
int firstNumOrDefault = numbers.FirstOrDefault();
.SingleOrDefault() ?
- Last()
- LastOrDefault()
- ElementAt()
(from n in numbers where n } 5 select n).ElementAt(1);
3. Generators operators
- Range()
From n in Enumerable.Range(100, 50) select (Number: n, OddEven: n % 2 == 1 ? "odd" : "even");
- Repeat()
var numbers = Enumerable.Repeat(7, 10);
4. Quantifiers
- * Any()
bool iAfterE = words.Any(w =} w.Contains("ei"));
- All()
bool onlyOdd = numbers.All(n =} n % 2 == 1);
5. Aggregate Operators
- * Count()
int uniqueFactors = factorsOf300.Distinct().Count();
- Sum()
double numSum = numbers.Sum();
- Min()
int minNum = numbers.Min();
- Max()
int maxNum = numbers.Max();
- Average()
double averageNum = numbers.Average();
- Aggregate()
double endBalance = attemptedWithdrawals.Aggregate(startBalance, (balance, nextWithdrawal) =} ((nextWithdrawal {= balance) ? (balance - nextWithdrawal) : balance));
6. Sequence Operations
- Concat – 지연 실행
Var allNumbers = numbersA.Concat(numbersB);
Union과 비슷하나 중복 제거를 안함
- Zip – 지연 실행
Int dotProduct = vectorA.Zip(vectorB, (a, b) =} a * b).Sum();
각 시퀀스에 인덱스를 이용해서 병합
- SequenceEqual
bool match = wordsA.SequenceEqual(wordsB);
7. Query Execution
- Deferred Execution 지연 실행
var q = from n in numbers select ++i;
Foreach (var v in q) { Console.WriteLine($”v={v}, i={i}”); }
- Forcing Immediate Execution 바로 실행
var q = (from n in numbers select ++i).ToList();
Foreach (var v in q) { Console.WriteLine($”v={v}, i={i}”); }
- Reuse Query
var lowNumbers = from n in numbers where n {= 3 select n;
8. Join Operations
- Cross Join
from c in categories join p in products on c equals p.Category select (Category: c, p.ProductName);
- Group Join
from c in categories join p in products on c equals p.Category into ps select (Category: c, Products: ps);
- Cross Group Join
from c in categories join p in products on c equals p.Category into ps from p in ps select (Category: c, p.ProductName);
- Left Outer Join
from c in categories join p in products on c equals p.Category into ps from p in ps.DefaultIfEmpty() select (Category: c, ProductName: p == null ? "(No products)" : p.ProductName);
- Right Outer Join? 다중키인 경우?
- 메뉴 항목 추가/삭제 화면에 등록 메뉴와 미등록 메뉴를 분리해서 보여주는 경우 사용
var allMenus = CMenus.CMenuList;
var regMenus = new List
{
new CMenu{ MenuId = 1, ParentId = 0, DisplayName = "Menu1"},
new CMenu{ MenuId = 3, ParentId = 0, DisplayName = "Menu3"},
new CMenu{ MenuId = 5, ParentId = 0, DisplayName = "Menu5"},
new CMenu{ MenuId = 12, ParentId = 1, DisplayName = "Menu12"},
new CMenu{ MenuId = 14, ParentId = 1, DisplayName = "Menu14"},
};
var unregMenus = from aMenu in allMenus
join rMenu in regMenus
on aMenu.MenuId equals rMenu.MenuId into joiner
from j in joiner.DefaultIfEmpty()
where j == null
select aMenu;
foreach (var menu in unregMenus)
{
Console.WriteLine($"{menu.MenuId}, {menu.ParentId}, {menu.DisplayName}");
}
'UWP & Windows App > Beginner' 카테고리의 다른 글
Create a UWP app with File System Access (0) | 2020.07.24 |
---|---|
Install and update UWP apps from the Web (0) | 2020.04.25 |
LINQ part 4 (0) | 2020.02.11 |
LINQ part 3 (0) | 2020.02.04 |
LINQ part2 (0) | 2020.01.31 |
- Total
- Today
- Yesterday
- kiosk
- Build 2016
- WPF
- uno platform
- Behavior
- LINQ
- #prism
- Visual Studio 2022
- MVVM
- UWP
- ef core
- Bot Framework
- Windows 10
- IOT
- C#
- #MVVM
- dotNETconf
- .net
- Cross-platform
- ComboBox
- Microsoft
- Always Encrypted
- XAML
- visual studio 2019
- #Windows Template Studio
- PRISM
- #uwp
- uno-platform
- .net 5.0
- windows 11
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | 7 |
8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 | 23 | 24 | 25 | 26 | 27 | 28 |
29 | 30 | 31 |