01 | using System; |
02 | using System.Collections.Generic; |
03 | using System.Linq; |
04 | using System.Text; |
05 | using System.IO; |
06 |
07 | namespace ConsoleApplication5 |
08 | { |
09 | class Program |
10 | { |
11 | static void Main( string [] args) |
12 | { |
13 | List<order> order = new List<order> { |
14 | new Order {Products = "노트북" , Company = "삼성" , Price = 195}, |
15 | new Order {Products = "노트북" , Company = "LG" , Price = 200}, |
16 | new Order {Products = "노트북" , Company = "HP" , Price = 190}, |
17 | new Order {Products = "노트북" , Company = "SONY" , Price = 220}, |
18 | new Order {Products = "노트북" , Company = "DELL" , Price = 180}, |
19 | new Order {Products = "노트북" , Company = "삼성" , Price = 170}, |
20 | new Order {Products = "노트북" , Company = "LG" , Price = 190}, |
21 | new Order {Products = "노트북" , Company = "HP" , Price = 180}, |
22 | new Order {Products = "노트북" , Company = "SONY" , Price = 240}, |
23 | new Order {Products = "노트북" , Company = "DELL" , Price = 170}, |
24 | new Order {Products = "컴퓨터" , Company = "삼성" , Price = 115}, |
25 | new Order {Products = "컴퓨터" , Company = "LG" , Price = 105}, |
26 | new Order {Products = "컴퓨터" , Company = "HP" , Price = 120}, |
27 | new Order {Products = "컴퓨터" , Company = "SONY" , Price = 130}, |
28 | new Order {Products = "컴퓨터" , Company = "DELL" , Price = 100}, |
29 | new Order {Products = "컴퓨터" , Company = "삼성" , Price = 125}, |
30 | new Order {Products = "컴퓨터" , Company = "LG" , Price = 115}, |
31 | new Order {Products = "컴퓨터" , Company = "HP" , Price = 125}, |
32 | new Order {Products = "컴퓨터" , Company = "SONY" , Price = 135}, |
33 | new Order {Products = "컴퓨터" , Company = "DELL" , Price = 110} |
34 | }; |
35 |
36 | /* 모두 가져오기 */ |
37 | var allSelect = from item in order select item; |
38 | foreach (var item in allSelect) |
39 | { |
40 | Console.WriteLine( "제품명 : {0}({1}), 가격 : {2}" , |
41 | item.Products, item.Company, item.Price); |
42 | } |
43 |
44 | /* where */ |
45 | Console.WriteLine( "--= 190보다 낮은 가격의 제품들 =--" ); |
46 | var where = from item in order where item.Price < 190 select item; |
47 | foreach (var item in where) |
48 | { |
49 | Console.WriteLine( "제품명 : {0}({1}), 가격 : {2}" , |
50 | item.Products, item.Company, item.Price); |
51 | } |
52 |
53 | /* group */ |
54 | var group = from item in order group item by item.Company; |
55 | foreach (var item in group) |
56 | { |
57 | Console.WriteLine( "====================" ); |
58 | Console.WriteLine( " {0} 회사 제품" ); |
59 | Console.WriteLine( "====================" ); |
60 |
61 | foreach (var item2 in item) |
62 | { |
63 | Console.WriteLine( "제품명 : {0}({1}), 가격 : {2}" , |
64 | item2.Products, item2.Company, item2.Price); |
65 | } |
66 | Console.WriteLine(); |
67 | } |
68 |
69 | /* where 2 */ |
70 | Console.WriteLine( "--= HP회사의 190보다 낮은 가격 제품들 =--" ); |
71 | var where2 = |
72 | from item in order where item.Company == "HP" && item.Price < 190 select item; |
73 | foreach (var item in where2) |
74 | { |
75 | Console.WriteLine( "제품명 : {0}({1}), 가격 : {2}" , |
76 | item.Products, item.Company, item.Price); |
77 | } |
78 |
79 | /* orderby */ |
80 | var orderby = |
81 | from item in order orderby item.Company ascending, item.Price descending select item; |
82 | foreach (var item in orderby) |
83 | { |
84 | Console.WriteLine( "제품명 : {0}({1}), 가격 : {2}" , |
85 | item.Products, item.Company, item.Price); |
86 | } |
87 |
88 | Console.ReadLine(); |
89 | } |
90 | } |
91 |
92 | class Order |
93 | { |
94 | public string Products { get ; set ; } |
95 | public string Company { get ; set ; } |
96 | public int Price { get ; set ; } |
97 | } |
98 | } |
99 | </order></order> |