3๋ฒˆ์งธ ์Šคํ„ฐ๋”” ์ดํ›„ ์ •๋ฆฌ
ยท
๐Ÿ’ป Programming Language/C#
ํ˜•๋ณ€ํ™˜๊ณผ ๊ด€๋ จํ•˜์—ฌ ... as ์—ฐ์‚ฐ์ž๋Š” ์ฐธ์กฐํ˜•์—๋งŒ ์‚ฌ์šฉ์ด ๊ฐ€๋Šฅํ•˜๊ณ  ๊ธฐ๋ณธ ๊ฐ’ํ˜•์‹์—๋Š” ์‚ฌ์šฉ์ด ๋ถˆ๊ฐ€๋Šฅํ•˜๋‹ค. ๊ธฐ๋ณธ ๊ฐ’ ํ˜•์‹์—๋Š” int, byte, char, long ... ๊ธฐ๋ณธ ๊ฐ’ ํ˜•์‹์— nullable => ? ํ‚ค์›Œ๋“œ๋Š” ์„ ์–ธ๋ฌธ์— ๋“ค์–ด๊ฐ€๋Š” ํ‚ค์›Œ๋“œ์ด๊ธฐ์— ์‚ฌ์šฉ๊ฐ€๋Šฅ int => value ํƒ€์ž… INTEGER => reference ํƒ€์ž… string ์€ ๊ธฐ๋ณธ ์ฐธ์กฐํ˜•์ด๋ผ๊ณ  ๋ฌธ์„œ์— ๋‚˜์˜ค๋Š”๋ฐ ์™œ ์•ˆ๋ ๊นŒ?? string์€ ์ฐธ์กฐ ํ˜•์‹์ด์ง€๋งŒ string๋Š” ์ฐธ์กฐ๊ฐ€ ์•„๋‹ˆ๋ผ string ๊ฐœ์ฒด์˜ ๊ฐ’์„ ๋น„๊ตํ•˜๋„๋ก ์ •์˜๋œ๋‹ค String ๊ณผ string ์˜ ์ฐจ์ด๋Š” ์—†๋‹ค. ๋‹ค๋งŒ string์ด System.String ํด๋ž˜์Šค๋ฅผ ์ƒ์†๋ฐ›์•„ ๊ตฌ์„ฑ๋˜์—ˆ๋‹ค. ๋ณดํ†ต string ์„ ์‚ฌ์šฉํ•  ๊ฒƒ์„ ๊ถŒ์žฅํ•˜๊ธดํ•œ๋‹ค. string a = "hello"; string..
์Šคํ„ฐ๋””) ๋‘๋ฒˆ์งธ ์Šคํ„ฐ๋”” ํ”ผ๋“œ๋ฐฑ ๋ฐ ์งˆ๋ฌธ ์ •๋ฆฌ๋‚ด์šฉ
ยท
๐Ÿ’ป Programming Language/C#
sealed ํ‚ค์›Œ๋“œ๋ฅผ ๋ฉ”์†Œ๋“œ์— ์‚ฌ์šฉ! ๋ถ€๋ชจํด๋ž˜์Šค์—์„œ ์˜ค์ž‘๋™์„ ํ•˜๊ฒŒ๋” ํ•˜๋Š” ์ž์›์„ ์ž์‹ํด๋ž˜์Šค์—์„œ ๊ฑด๋“œ๋ฆฌ๋ฉด ์•ˆ๋˜๋Š” ๊ฒฝ์šฐ ๋ฉ”์†Œ๋“œ์— sealed ํ•œ์ •์ž๋ฅผ ์‚ฌ์šฉํ•ด์„œ ์ œํ•œํ•  ์ˆ˜ ์žˆ๋‹ค. class Parent { public int num; public int count; public Parent(int num) { this.num = num; this.count = 0; Console.WriteLine("Parent ์ƒ์„ฑ์ž"); } public virtual void addCount() { } public void showInfo() { Console.WriteLine("Num : {0}, Count : {1}", this.num, this.count); } } class Counter : Parent { publ..
์Šคํ„ฐ๋””) ์ฒซ๋ฒˆ์งธ ์Šคํ„ฐ๋”” ํ”ผ๋“œ๋ฐฑ ๋ฐ ์งˆ๋ฌธ ์ •๋ฆฌ๋‚ด์šฉ
ยท
๐Ÿ’ป Programming Language/C#
1. ์ฐธ์กฐ ํ˜•์‹์„ ๋ฉ”์†Œ๋“œ์˜ ๋งค๊ฐœ๋ณ€์ˆ˜๋กœ ๋„˜๊ฒจ ํ• ๋‹น ํ›„ ๋ณ€ํ™”๋ฅผ ์ฃผ๋ฉด ์–ด๋–ป๊ฒŒ ๋ ๊นŒ? class MyField { public int field1; public int field2; } class AssignRefType { public static void addVal(MyField obj) { MyField temp = obj; temp.field1++; temp.field2++; } public static void subVal(MyField obj) { MyField temp = obj; temp.field1--; temp.field2--; } static void Main(string[] args) { MyField mf = new MyField() { field1 = 1, field2 = 2 }; M..
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 ์œผ๋กœ ์ง€์ •๋˜์–ด ์žˆ๋‹ค. ๋‚ด๋ฆผ์ฐจ์ˆœ..