40. C#LYNQ(링크) – GROUP BY INTO, 닷넷LYNQ
[형식]
Group A by B into C
e
A는 from절의 범위 변수, B는 분류(그룹핑) 기준, C는 그룹변수 이다.
예제를 통해서 이해하자.
using System;
using System.Linq;
using System.Collections.Generic;
namespace from
{
class OnjProfile
{
public string Name { get; set; }
public int Age { get; set; }
}
class Onj
{
static void Main(string[] args)
{
OnjProfile[] onjProfile = {
new OnjProfile() {Name="ONJSYSTEM", Age=8},
new OnjProfile() {Name="오라클자바커뮤니티프로그래밍실무학원", Age=6},
new OnjProfile() {Name="오라클자바커뮤니티", Age=13}
};
var onjs = from onj in onjProfile
orderby onj.Name
group onj by onj.Age >= 7 into g
select new
{
GroupKey = g.Key,
Profiles = g
};
foreach (var g in onjs)
{
Console.WriteLine("7년이상 {0}", g.GroupKey);
foreach (var profile in g.Profiles)
{
Console.WriteLine(" {0}, {1}",profile.Name, profile.Age);
}
}
}
}
}
[결과]
7년이상 True
ONJSYSTEM, 8
오라클자바커뮤니티, 13
7년이상 False
오라클자바커뮤니티프로그래밍실무학원, 6
![]() | ![]() ![]() | 12-27 | 2708 | |
![]() | ![]() ![]() | 12-11 | 1956 | |
53 | ![]() ![]() | 03-15 | 1781 | |
52 | ![]() ![]() | 01-31 | 1936 | |
51 | ![]() ![]() | 01-31 | 2831 | |
50 | ![]() ![]() | 01-31 | 1487 | |
49 | ![]() ![]() | 01-19 | 1819 | |
48 | ![]() ![]() | 01-11 | 1694 | |
47 | ![]() ![]() | 01-03 | 2237 | |
46 | ![]() ![]() | 12-27 | 2708 | |
45 | ![]() ![]() | 12-19 | 1916 | |
44 | ![]() ![]() | 12-14 | 1894 | |
43 | ![]() ![]() | 12-11 | 1956 | |
42 | ![]() ![]() | 12-09 | 1541 | |
41 | ![]() ![]() | 12-01 | 1767 | |
40 | ![]() ![]() | 12-01 | 1973 | |
39 | ![]() ![]() | 12-01 | 1410 |
댓글 없음:
댓글 쓰기