43. ์Šค๋ ˆ๋“œ์™€ ํƒœ์Šคํฌ
ยท
๐Ÿ’ป Programming Language/C#
ํ”„๋กœ์„ธ์Šค(Process) : ์‹คํ–‰ํŒŒ์ผ์ด ์‹คํ–‰๋˜์–ด ๋ฉ”๋ชจ๋ฆฌ์— ์ ์žฌ๋œ ์ธ์Šคํ„ด์Šค ํ”„๋กœ์„ธ์Šค๋Š” ํ•˜๋‚˜ ์ด์ƒ์˜ ์Šค๋ ˆ๋“œ(Thread)๋กœ ๊ตฌ์„ฑ๋œ๋‹ค. ์Šค๋ ˆ๋“œ๋Š” ์šด์˜์ฒด์ œ๊ฐ€ CPU๋ฅผ ํ• ๋‹นํ•˜๋Š” ๊ธฐ๋ณธ๋‹จ์œ„์ด๋ฉฐ, ํ”„๋กœ์„ธ์Šค๊ฐ€ ๋ฐง์ค„์ด๋ผ๋ฉด, ์Šค๋ ˆ๋“œ๋Š” ๋ฐง์ค„์„ ์ด๋ฃจ๊ณ  ์žˆ๋Š” ์‹ค์ด๋ผ๊ณ  ํ•  ์ˆ˜ ์žˆ๋‹ค. ๋ฉ€ํ‹ฐ ์Šค๋ ˆ๋“œ(Multi-Thread)๋ฅผ ์ด์šฉํ–ˆ์„๋•Œ์˜ ์žฅ๋‹จ์ . ์žฅ์  ์‚ฌ์šฉ์ž ๋Œ€ํ™”ํ˜• ํ”„๋กœ๊ทธ๋žจ์—์„œ(์ฝ˜์†” ํ”„๋กœ๊ทธ๋žจ๊ณผ GUIํ”„๋กœ๊ทธ๋žจ ๋ชจ๋‘) ๋ฉ€ํ‹ฐ์Šค๋ ˆ๋“œ๋ฅผ ์ด์šฉํ•˜๋ฉด ์‘๋‹ต์„ฑ์„ ๋†’์ผ ์ˆ˜ ์žˆ๋‹ค๋Š” ์ ์„ ๊ผฝ์„ ์ˆ˜ ์žˆ๋‹ค. ์˜ˆ๋ฅผ ๋“ค์–ด ์šฐ๋ฆฌ๊ฐ€ ๋งŒ๋“  ํ”„๋กœ๊ทธ๋žจ์„ ํŒŒ์ผ์„ ๋ณต์‚ฌํ•˜๋Š”๋ฐ, ๋ณต์‚ฌํ•  ํ”ผ์ผ์ด ๋„ˆ๋ฌด ์ปค์„œ ์†Œ์š”์‹œ๊ฐ„์ด 30๋ถ„์ •๋„ ๊ฑธ๋ฆฐ๋‹ค๊ณ  ๊ฐ€์ •ํ•ด๋ณด์ž. ์ด ๋•Œ ํ”„๋กœ๊ทธ๋žจ์„ ๋‹จ์ผ ์Šค๋ ˆ๋“œ๋กœ ๋งŒ๋“ ๋‹ค๋ฉด ํ”„๋กœ๊ทธ๋žจ์ด ํŒŒ์ผ์„ ๋ณต์‚ฌํ•˜๋Š” ๋™์•ˆ ์‚ฌ์šฉ์ž๊ฐ€ ์ทจ์†Œ ๋ช…๋ น์„ ๋‚ด๋ฆฌ๊ณ  ์‹ถ์–ด๋„ ํ”„๋กœ๊ทธ๋žจ์ด ์‚ฌ์šฉ์ž์—๊ฒŒ ๋ฐ˜์‘..
42. LINQ ์„ธ๋ถ€ ๋ฌธ๋ฒ•
ยท
๐Ÿ’ป Programming Language/C#
๋‘ ๊ฐœ์˜ from ์ ˆ์„ ์ด์šฉํ•œ LINQ ๋ฌธ using System.Collections; namespace LINQEx { class MemberScore { public string Name { get; set; } public int[] Score { get; set; } } class Program { static void Main(string[] args) { MemberScore[] ms = { new MemberScore(){Name="ํ™๊ธธ๋™",Score=new int[]{30, 42, 67 } }, new MemberScore(){Name="์ฒญ๊ธธ๋™",Score=new int[]{88, 45, 87 } }, new MemberScore(){Name="๋…น๊ธธ๋™",Score=new int[]{55,..
41. ์ต๋ช… Type
ยท
๐Ÿ’ป Programming Language/C#
์ต๋ช… ํƒ€์ž…(๋ฌด๋ช… ํƒ€์ž…, Anonymous Type) : ์ผ๋ฐ˜์ ์œผ๋กœ ํด๋ž˜์Šค๋ฅผ ์‚ฌ์šฉํ•˜๊ธฐ ์œ„ํ•ด์„œ๋Š” ํด๋ž˜์Šค๋ฅผ ์ •์˜ํ•œ ํ›„์— ์‚ฌ์šฉํ•œ๋‹ค. C# 3.0์—์„œ๋Š” ํด๋ž˜์Šค๋ฅผ ๋ฏธ๋ฆฌ ์ •์˜ํ•˜์ง€ ์•Š๊ณ  ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋„๋ก ์ต๋ช…ํƒ€์ž… ๊ธฐ๋Šฅ์„ ์ง€์›ํ•˜๊ฒŒ๋จ. ์ต๋ช… ํƒ€์ž… ํ˜•์‹ new {์†์„ฑ1 = ๊ฐ’, ์†์„ฑ2 = ๊ฐ’}; Ex) var c = new {name = "ํ™๊ธธ๋™", age = 22}; ์ต๋ช…ํƒ€์ž… ์‚ฌ์šฉ ์˜ˆ์ œ ์ฝ”๋“œ using System.Collections; namespace AnonymousTypeEx { class Program { static void Main(string[] args) { var v = new { name = "๋…น๊ธธ๋™", age = 55 }; Console.WriteLine($"์ด๋ฆ„ : {v.name} ๋‚˜์ด : {v.a..
40. LINQ ๊ธฐ๋ณธ ๋ฌธ๋ฒ•
ยท
๐Ÿ’ป Programming Language/C#
using System.Collections; /* [LINQ] LINQ์˜ ์งˆ์˜ํ‘œํ˜„์‹ = ์ฟผ๋ฆฌ ์‹ (Query Expression) ์€ from ์ ˆ๋กœ ์‹œ์ž‘ํ•œ๋‹ค. - from ์ ˆ ๋‹ค์Œ์—๋Š” ๋ฐ์ดํ„ฐ ์›๋ณธ์ด ์˜จ๋‹ค. ๋ฐ์ดํ„ฐ ์›๋ณธ์€ ๋ฐฐ์—ด, ์ปฌ๋ ‰์…˜ ๋“ฑ์ด ์˜ฌ ์ˆ˜ ์žˆ๋‹ค. - from in ```csharp int[] aaa = {11,22,33,44,55} var res = from a in aaa where a % 2 != 0 orderby a select a; ``` - where ์ ˆ์€ ๋ฒ”์œ„ ๋ณ€์ˆ˜์˜ ์กฐ๊ฑด์„ ์ง€์ •ํ•˜์—ฌ ๊ทธ ์กฐ๊ฑด์— ํ•ด๋‹นํ•˜๋Š” ๋ฐ์ดํ„ฐ๋ฅผ ๊ฑธ๋Ÿฌ๋‚ด๋Š” ์—ญํ• ์„ ํ•œ๋‹ค. - orderby์ ˆ์€ where ์ ˆ์—์„œ ๊ฑธ๋Ÿฌ๋‚ธ ๋ฐ์ดํ„ฐ๋ฅผ ์ •๋ ฌํ•˜๋Š” ์—ญํ• ์„ ํ•œ๋‹ค. - ๊ธฐ๋ณธ ์ •๋ ฌ๊ฐ’์€ ์˜ค๋ฆ„์ฐจ์ˆœ ascending ์œผ๋กœ ์ง€์ •๋˜์–ด ์žˆ๋‹ค. ๋‚ด๋ฆผ์ฐจ์ˆœ..
39. LINQ ์‚ฌ์šฉํ•ด๋ณด๊ธฐ
ยท
๐Ÿ’ป Programming Language/C#
LINQ, ORM => SQL๋ฌธ๊ณผ๋Š” ๋‹ค๋ฅด๊ฒŒ DB๋กœ๋ถ€ํ„ฐ ํ•„์š”ํ•œ ๋ฐ์ดํ„ฐ๋ฅผ ํŽธ๋ฆฌํ•˜๊ฒŒ ๊ฐ€์ ธ์˜ด. LINQ(Language Integrated Query) : C# ์–ธ์–ด์— ํ†ตํ•ฉ๋œ ๋ฐ์ดํ„ฐ ์งˆ์˜ ๊ธฐ๋Šฅ using System.Collections; namespace LinqEx { class Member { public string name { get; set; } public int age { get; set; } } class Program { static void Main(string[] args) { Member[] ml = { new Member(){name = "ํ™๊ธธ๋™" , age =23}, new Member(){name = "์ฒญ๊ธธ๋™" , age =24}, new Member(){name = "๋ฐฑ๊ธธ๋™" , ..
38. ๋žŒ๋‹ค์‹(Lambda Expression)
ยท
๐Ÿ’ป Programming Language/C#
๋žŒ๋‹ค์‹ : ์ต๋ช… ๋ฉ”์†Œ๋“œ๋ฅผ ๋งŒ๋“ค๊ธฐ ์œ„ํ•ด ์‚ฌ์šฉํ•˜๋Š” ์‹ ๋žŒ๋‹ค์‹์œผ๋กœ ๋งŒ๋“ค์–ด์ง„ ์ต๋ช… ๋ฉ”์†Œ๋“œ๋ฅผ ๋ฌด๋ช… ํ•จ์ˆ˜(Anonymous Function) ๋ผ๊ณ  ํ•œ๋‹ค. ๋žŒ๋‹ค์‹ ์„ ์–ธ ํ˜•์‹ ๋งค๊ฐœ๋ณ€์ˆ˜ ๋ชฉ๋ก => ์‹ => ์—ฐ์‚ฐ์ž๋ฅผ ์ž…๋ ฅ ์—ฐ์‚ฐ์ž๋ผ๊ณ  ํ•œ๋‹ค. delegate int AAA(int x, int y); static void Main(string[] args){ AAA aaa = (int x,int y) => x + y; } (int x, int y) => x + y ๋ผ๋Š” ์ต๋ช… ๋ฉ”์†Œ๋“œ๊ฐ€ delegate ์ธ aaa์— ์ „๋‹ฌ๋˜๊ณ  ์žˆ๋Š” ๋ชจ์Šต ์œ„์˜ ์ฝ”๋“œ๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™์ด ๋ฐ”๊ฟ”์„œ ์‚ฌ์šฉ ๊ฐ€๋Šฅ AAA aaa = (x, y) => x + y; delegate์˜ ์ธ์ž์— ํƒ€์ž…์ด ์„ ์–ธ๋˜์–ด ์žˆ๊ธฐ์— ๊ฐ€๋Šฅ ์œ„์˜ ์ต๋ช… ๋ฉ”์†Œ๋“œ(๋ฌด๋ช…ํ•จ์ˆ˜)๋Š” ๊ธฐ์กด์— ์ต๋ช… ๋ฉ”์†Œ๋“œ๋ฅผ ์‚ฌ..
37. ๋ธ๋ฆฌ๊ฒŒ์ดํŠธ๋ฅผ ํ†ตํ•œ ์ด๋ฒคํŠธ ์ฒ˜๋ฆฌ
ยท
๐Ÿ’ป Programming Language/C#
์ด๋ฒคํŠธ : ํŠน์ •ํ•œ ์ผ์ด ์ผ์–ด๋‚ฌ์Œ์„ ์•Œ๋ ค์ฃผ๋Š” ๊ธฐ๋Šฅ C# ์—์„œ๋Š” ์ด๋ฒคํŠธ๋ฅผ ๋ธ๋ฆฌ๊ฒŒ์ดํŠธ(delegate)์™€ ํ•จ๊ป˜ ์‚ฌ์šฉํ•œ๋‹ค. event ํ‚ค์›Œ๋“œ๋ฅผ ์ด์šฉํ•˜์—ฌ ํ‘œ์‹œํ•œ๋‹ค. ์ด๋ฒคํŠธ ์„ ์–ธ๊ณผ ์‚ฌ์šฉ ์ˆœ์„œ 1. delegate๋ฅผ ์„ ์–ธ 2. ์„ ์–ธ๋œ delegate์— event ํ‚ค์›Œ๋“œ๋ฅผ ๋ถ™์—ฌ์ค€๋‹ค. 3. event handler๋ฅผ ์ž‘์„ฑํ•œ๋‹ค. ์„ ์–ธ๋œ delegate์˜ ํ”„๋กœํ† ํƒ€์ž…๊ณผ ๋™์ผํ•˜๊ฒŒ ๋ฉ”์†Œ๋“œ๋ฅผ ์ž‘์„ฑ. => ์ด๋•Œ event handler๋Š” delegate ์„ ์–ธ์‹œ์— ํ”„๋กœํ† ํƒ€์ž…๊ณผ ๋™์ผํ•œ ๋ฉ”์†Œ๋“œํ˜•ํƒœ๋กœ ์ž‘์„ฑํ•œ๋‹ค. 4. ํด๋ž˜์Šค์˜ ์ธ์Šคํ„ด์Šค๋ฅผ ์ƒ์„ฑํ•˜๊ณ , ์ด ๊ฐ์ฒด์— ์ด๋ฒคํŠธ ํ•ธ๋“ค๋Ÿฌ๋ฅผ ๋“ฑ๋ก 5. ์ด๋ฒคํŠธ๊ฐ€ ๋ฐœ์ƒํ•˜๋ฉด ์ด๋ฒคํŠธ ํ•ธ๋“ค๋Ÿฌ ํ˜ธ์ถœ using System.Collections; namespace EventEx { delegate void EventHa..