parent
54944d5a16
commit
ea54dc68fb
@ -0,0 +1,24 @@ |
|||||||
|
{ |
||||||
|
// IntelliSense를 사용하여 가능한 특성에 대해 알아보세요. |
||||||
|
// 기존 특성에 대한 설명을 보려면 가리킵니다. |
||||||
|
// 자세한 내용을 보려면 https://go.microsoft.com/fwlink/?linkid=830387을(를) 방문하세요. |
||||||
|
"version": "0.2.0", |
||||||
|
"configurations": [ |
||||||
|
{ |
||||||
|
"name": ".NET Core Launch (console)", |
||||||
|
"type": "coreclr", |
||||||
|
"request": "launch", |
||||||
|
"preLaunchTask": "build", |
||||||
|
"program": "${workspaceFolder}/DevTips/bin/Debug/net7.0/DevTips.dll", |
||||||
|
"args": [], |
||||||
|
"cwd": "${workspaceFolder}/DevTips", |
||||||
|
"console": "internalConsole", |
||||||
|
"stopAtEntry": false |
||||||
|
}, |
||||||
|
{ |
||||||
|
"name": ".NET Core Attach", |
||||||
|
"type": "coreclr", |
||||||
|
"request": "attach" |
||||||
|
} |
||||||
|
] |
||||||
|
} |
@ -0,0 +1,41 @@ |
|||||||
|
{ |
||||||
|
"version": "2.0.0", |
||||||
|
"tasks": [ |
||||||
|
{ |
||||||
|
"label": "build", |
||||||
|
"command": "dotnet", |
||||||
|
"type": "process", |
||||||
|
"args": [ |
||||||
|
"build", |
||||||
|
"${workspaceFolder}/DevTips/DevTips.csproj", |
||||||
|
"/property:GenerateFullPaths=true", |
||||||
|
"/consoleloggerparameters:NoSummary" |
||||||
|
], |
||||||
|
"problemMatcher": "$msCompile" |
||||||
|
}, |
||||||
|
{ |
||||||
|
"label": "publish", |
||||||
|
"command": "dotnet", |
||||||
|
"type": "process", |
||||||
|
"args": [ |
||||||
|
"publish", |
||||||
|
"${workspaceFolder}/DevTips/DevTips.csproj", |
||||||
|
"/property:GenerateFullPaths=true", |
||||||
|
"/consoleloggerparameters:NoSummary" |
||||||
|
], |
||||||
|
"problemMatcher": "$msCompile" |
||||||
|
}, |
||||||
|
{ |
||||||
|
"label": "watch", |
||||||
|
"command": "dotnet", |
||||||
|
"type": "process", |
||||||
|
"args": [ |
||||||
|
"watch", |
||||||
|
"run", |
||||||
|
"--project", |
||||||
|
"${workspaceFolder}/DevTips/DevTips.csproj" |
||||||
|
], |
||||||
|
"problemMatcher": "$msCompile" |
||||||
|
} |
||||||
|
] |
||||||
|
} |
@ -0,0 +1,10 @@ |
|||||||
|
<Project Sdk="Microsoft.NET.Sdk"> |
||||||
|
|
||||||
|
<PropertyGroup> |
||||||
|
<OutputType>Exe</OutputType> |
||||||
|
<TargetFramework>net7.0</TargetFramework> |
||||||
|
<ImplicitUsings>enable</ImplicitUsings> |
||||||
|
<Nullable>enable</Nullable> |
||||||
|
</PropertyGroup> |
||||||
|
|
||||||
|
</Project> |
@ -0,0 +1,101 @@ |
|||||||
|
using System.Data; |
||||||
|
using System.Collections.Generic; |
||||||
|
using System.Linq; |
||||||
|
|
||||||
|
namespace DevTips.Tips |
||||||
|
{ |
||||||
|
class LinqGroupMinMax |
||||||
|
{ |
||||||
|
public static void Print() |
||||||
|
{ |
||||||
|
DataTable table = GetData(); |
||||||
|
foreach (DataRow row in table.Rows) |
||||||
|
{ |
||||||
|
System.Console.WriteLine($"\t{row["GroupID"]}\t{row["SalesPerson"]}\t{row["Sales"]}"); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public static void Client1() |
||||||
|
{ |
||||||
|
var data = GetData().AsEnumerable(); |
||||||
|
|
||||||
|
var result = from row in data |
||||||
|
group row by row.Field<int>("GroupID") into g |
||||||
|
select new |
||||||
|
{ |
||||||
|
GroupID = g.Key, |
||||||
|
SalesPerson = g.First(g2 => g2.Field<int>("Sales") == g.Min(g3 => g3.Field<int>("Sales"))).Field<string>("SalesPerson"), |
||||||
|
Sales = g.Min(p => p.Field<int>("Sales")) |
||||||
|
}; |
||||||
|
|
||||||
|
foreach (var r in result) |
||||||
|
{ |
||||||
|
System.Console.WriteLine($"{r.GroupID},{r.SalesPerson} , {r.Sales}"); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public static void Client2() |
||||||
|
{ |
||||||
|
var data = GetData().AsEnumerable(); |
||||||
|
|
||||||
|
var result = data.GroupBy(t => t.Field<int>("GroupID")).Select(g => new |
||||||
|
{ |
||||||
|
GroupID = g.Key, |
||||||
|
SalesPerson = g.First(g2 => g2.Field<int>("Sales") == g.Min(g3 => g3.Field<int>("Sales"))).Field<string>("SalesPerson"), |
||||||
|
Sales = g.Min(p => p.Field<int>("Sales")) |
||||||
|
}); |
||||||
|
} |
||||||
|
|
||||||
|
private static DataTable GetData() |
||||||
|
{ |
||||||
|
DataTable table = new DataTable(); |
||||||
|
table.Columns.Add("GroupID", typeof(int)); |
||||||
|
table.Columns.Add("SalesPerson", typeof(string)); |
||||||
|
table.Columns.Add("Sales", typeof(int)); |
||||||
|
|
||||||
|
DataRow row = table.NewRow(); |
||||||
|
row["GroupID"] = 1; |
||||||
|
row["SalesPerson"] = "Lee"; |
||||||
|
row["Sales"] = 900; |
||||||
|
table.Rows.Add(row); |
||||||
|
|
||||||
|
row = table.NewRow(); |
||||||
|
row["GroupID"] = 1; |
||||||
|
row["SalesPerson"] = "Li"; |
||||||
|
row["Sales"] = 800; |
||||||
|
table.Rows.Add(row); |
||||||
|
|
||||||
|
row = table.NewRow(); |
||||||
|
row["GroupID"] = 1; |
||||||
|
row["SalesPerson"] = "Park"; |
||||||
|
row["Sales"] = 990; |
||||||
|
table.Rows.Add(row); |
||||||
|
|
||||||
|
row = table.NewRow(); |
||||||
|
row["GroupID"] = 2; |
||||||
|
row["SalesPerson"] = "Tom"; |
||||||
|
row["Sales"] = 500; |
||||||
|
table.Rows.Add(row); |
||||||
|
|
||||||
|
row = table.NewRow(); |
||||||
|
row["GroupID"] = 2; |
||||||
|
row["SalesPerson"] = "Jane"; |
||||||
|
row["Sales"] = 400; |
||||||
|
table.Rows.Add(row); |
||||||
|
|
||||||
|
row = table.NewRow(); |
||||||
|
row["GroupID"] = 3; |
||||||
|
row["SalesPerson"] = "Irina"; |
||||||
|
row["Sales"] = 600; |
||||||
|
table.Rows.Add(row); |
||||||
|
|
||||||
|
row = table.NewRow(); |
||||||
|
row["GroupID"] = 3; |
||||||
|
row["SalesPerson"] = "Yong"; |
||||||
|
row["Sales"] = 633; |
||||||
|
table.Rows.Add(row); |
||||||
|
|
||||||
|
return table; |
||||||
|
} |
||||||
|
} |
||||||
|
} |
Loading…
Reference in new issue