syneffort 2 years ago
parent 4acd09f034
commit a474b715fd
  1. 3
      .vscode/settings.json
  2. 10
      AdvancedC#Grammer/MySolution/MyConsoleApp/MyConsoleApp.csproj
  3. 19
      AdvancedC#Grammer/MySolution/MyConsoleApp/Program.cs
  4. 47
      AdvancedC#Grammer/MySolution/MyConsoleApp/Work/AsyncAwaitWork.cs
  5. 160
      AdvancedC#Grammer/MySolution/MyConsoleApp/Work/LinqWork.cs
  6. 22
      AdvancedC#Grammer/MySolution/MySolution.sln
  7. 38
      HTML, CSS/test.html

@ -0,0 +1,3 @@
{
"dotnet.defaultSolution": "AdvancedC#Grammer/MySolution/MySolution.sln"
}

@ -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,19 @@
using MyConsoleApp.Work;
namespace MyConsoleApp;
class Program
{
static void Main(string[] args)
{
//AsyncAwaitWork.DoTest();
LinqWork.DoTest();
while (true)
{
}
}
}

@ -0,0 +1,47 @@
namespace MyConsoleApp.Work
{
public class AsyncAwaitWork
{
private static Task Test()
{
System.Console.WriteLine("Start Test");
Task t = Task.Delay(3000);
return t;
}
private static async void TestAsync()
{
System.Console.WriteLine("Start Test");
Task t = Task.Delay(3000);
await t; // 함수 내부에서는 동기, 함수 호출부에서는 비동기로 처리됨
System.Console.WriteLine("End TestAsync");
}
private static async Task<int> TestAsync2()
{
System.Console.WriteLine("Start Test");
Task t = Task.Delay(3000);
await t;
System.Console.WriteLine("End TestAsync");
return 1;
}
public async static void DoTest()
{
// Task t = Test();
// t.Wait();
//TestAsync();
await TestAsync2(); // 메인 함수도 동기로 처리됨
int res = await TestAsync2();
System.Console.WriteLine("While start");
while (true)
{
}
}
}
}

@ -0,0 +1,160 @@
using System.Diagnostics;
using System.Security.Cryptography;
namespace MyConsoleApp.Work
{
public class LinqWork
{
private static List<Player> _players = new List<Player>();
private static void InitInstance()
{
Random rand = new Random();
for (int i = 0; i < 100; i++)
{
ClassType type = ClassType.Knight;
switch (rand.Next(0, 3))
{
case 1:
type = ClassType.Archer;
break;
case 2:
type = ClassType.Mage;
break;
}
Player player = new Player()
{
ClassType = type,
Level = rand.Next(1, 100),
Hp = rand.Next(100, 1000),
Attack = rand.Next(5, 50)
};
for (int j = 0; j < 5; j++)
{
player.Items.Add(rand.Next(1, 100));
}
_players.Add(player);
}
}
public static void DoTest()
{
InitInstance();
// Q1) 레벨 50 이상인 Knight를 레벨 오름차순으로 정렬
Stopwatch sw = new Stopwatch();
sw.Start();
// Without Linq
{
List<Player> players = GetHighLevelKnight();
foreach (Player player in players)
{
System.Console.WriteLine($"[{player.Level}] {player.Hp}");
}
}
System.Console.WriteLine($"{sw.ElapsedMilliseconds}ms");
System.Console.WriteLine("---------------------");
sw.Restart();
// With Linq
{
var players =
from p in _players
where p.ClassType == ClassType.Knight && p.Level >= 50
orderby p.Level
select p;
foreach (Player player in players)
{
System.Console.WriteLine($"[{player.Level}] {player.Hp}");
}
}
System.Console.WriteLine($"{sw.ElapsedMilliseconds}ms");
// from 중첩
// Q2) id가 30 미만인 모든 아이템 목록 추출
{
var playerItems =
from p in _players
from i in p.Items
where i < 30
select new { p, i };
var li = playerItems.ToList();
System.Console.WriteLine($"Count: {li.Count}");
}
// grouping
{
var playerByLevel =
from p in _players
group p by p.Level into g
orderby g.Key
select new { g.Key, Players = g };
}
// join
{
List<int> levels = new List<int>() { 1, 5, 10 };
var players =
from p in _players
join l in levels
on p.Level equals l
select p;
}
// Linq 표준 연산자
{
var players =
from p in _players
where p.ClassType == ClassType.Knight && p.Level >= 50
orderby p.Level
select p;
var players2 = _players
.Where(p => p.ClassType == ClassType.Knight && p.Level >= 50)
.OrderBy(p => p.Level)
.Select(p => p);
}
}
private static List<Player> GetHighLevelKnight()
{
List<Player> players = new List<Player>();
foreach (Player player in _players)
{
if (player.ClassType != ClassType.Knight)
continue;
if (player.Level < 50)
continue;
players.Add(player);
}
players.Sort((lhs, rhs) => { return lhs.Level - rhs.Level; });
return players;
}
}
public enum ClassType
{
Knight,
Archer,
Mage,
}
public class Player
{
public ClassType ClassType { get; set; }
public int Level { get; set; }
public int Hp { get; set; }
public int Attack { get; set; }
public List<int> Items { get; set; } = new List<int>();
}
}

@ -0,0 +1,22 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.0.31903.59
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MyConsoleApp", "MyConsoleApp\MyConsoleApp.csproj", "{4904D5DC-9923-40EE-9550-E99B74754381}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{4904D5DC-9923-40EE-9550-E99B74754381}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4904D5DC-9923-40EE-9550-E99B74754381}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4904D5DC-9923-40EE-9550-E99B74754381}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4904D5DC-9923-40EE-9550-E99B74754381}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal

@ -19,6 +19,25 @@
td {
border: 1px solid salmon;
}
#para1 {
color: red;
font-weight: bold;
text-align: center;
}
.center {
text-align: center;
}
div {
background-color: lightblue;
width: 300px;
border: 15px solid green;
padding: 50px;
margin: 20px;
}
h1 {
border-bottom: 1px solid gray;
padding-bottom: 15px;
}
</style>
</head>
@ -30,12 +49,15 @@
<strong>enim ad minim veniam,</strong>
quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
consequat.<br />
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore
eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident,
sunt in culpa qui officia deserunt mollit anim id est laborum.
<span style="color: blueviolet; font-weight: bold">aute irure dolor</span>
in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla
pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui
officia deserunt mollit anim id est laborum.
<p>This is paragraph.</p>
<p id="para1">This is paragraph.</p>
<p>This is paragraph.</p>
<p class="center">This is paragraph.</p>
<p>This is paragraph.</p>
<img
@ -121,6 +143,16 @@
<input type="submit" value="Submit" />
</form>
<div>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim
veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea
commodo consequat. Duis aute irure dolor in reprehenderit in voluptate
velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat
cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id
est laborum.
</div>
<script>
function testFunc() {
alert('Call testFunc!');

Loading…
Cancel
Save