์ „์ฒด ๊ธ€

์ „์ฒด ๊ธ€

    17. C#์˜ ํด๋ž˜์Šค

    ํด๋ž˜์Šค๋Š” ๊ฐ์ฒด๋ฅผ ๋งŒ๋“ค๊ธฐ ์œ„ํ•œ ์ฒญ์‚ฌ์ง„ (์ฆ‰, ์„ค๊ณ„๋„) ํด๋ž˜์Šค(์„ค๊ณ„๋„) ๊ฐ์ฒด(์‹ค์ฒด) ํ˜•์‹ ๋˜๋Š” ์„ค๊ณ„๋„ ๋ฉ”๋ชจ๋ฆฌ์— ์ ์žฌ๋œ ์‹ค์ฒด ๊ฐ ํ˜•์‹/ํด๋ž˜์Šค ๋ณ„๋กœ ํ•˜๋‚˜๋งŒ ์กด์žฌ ์ด๋ก ์ ์œผ๋กœ๋Š” ๋ฌดํ•œ๋Œ€๋กœ ์ƒ์„ฑ ๊ฐ€๋Šฅํ•˜๋ฉฐ, ๋ฉ”๋ชจ๋ฆฌ๋ฅผ ์ฐจ์ง€ํ•จ ๊ฐ์ฒด๊ฐ€ ์–ด๋–ค ๋ฐ์ดํ„ฐ ํ•ญ๋ชฉ์„ ๊ฐ€์ง€๋Š”์ง€ ์ •์˜ ์„ ์–ธ๋œ ๋ฐ์ดํ„ฐ ํ•ญ๋ชฉ์— ์‹ค์ œ ๋ฐ์ดํ„ฐ ์ €์žฅ ์–ด๋–ค ๋ฉ”์†Œ๋“œ๋ฅผ ๊ฐ€์งˆ์ง€๋ฅผ ์ •์˜ ์ •์˜๋˜์–ด ์žˆ๋Š” ๋ฉ”์†Œ๋“œ๋ฅผ ์‹คํ–‰ ๊ฐ์ฒด ์ง€ํ–ฅ ํ”„๋กœ๊ทธ๋ž˜๋ฐ์€ OOP๋ผ๊ณ ๋„ ํ•˜๋Š”๋ฐ, ์ฝ”๋“œ ๋‚ด์˜ ๋ชจ๋“  ๊ฒƒ์„ ๊ฐ์ฒด๋กœ ํ‘œํ˜„ํ•˜๊ณ ์ž ํ•˜๋Š” ํ”„๋กœ๊ทธ๋ž˜๋ฐ ํŒจ๋Ÿฌ๋‹ค์ž„์„ ๋œปํ•œ๋‹ค. ๊ฐ์ฒด๋Š” ์„ธ์ƒ์˜ ๋ชจ๋“  ๊ฒƒ์„ ์ง€์นญํ•˜๋Š” ๋‹จ์–ด์ด๋‹ค. ์‚ฌ๋žŒ๋„ ๊ฐ์ฒด์ด๊ณ  ์—ฐํ•„๋„ ๊ฐ์ฒด์ด๊ณ  ๋ชจ๋“  ๊ฒƒ์ด ๊ฐ์ฒด์ด๋‹ค. ํ”„๋กœ๊ทธ๋ž˜๋จธ๋Š” ์ถ”์ƒ์ฃผ์˜ ์˜ˆ์ˆ ๊ฐ€๊ฐ€ ๋œ ๋งˆ๋ƒฅ ๊ฐ์ฒด์˜ ์ฃผ์š” ํŠน์ง•๋งŒ ๋ฝ‘์•„๋‚ด๋Š” ์ด๋ฅธ๋ฐ” ์ถ”์ƒํ™”๋ฅผ ํ•˜๊ฒŒ ๋œ๋‹ค. ๊ฐ์ฒด ์ง€ํ–ฅ ํ”„๋กœ๊ทธ๋ž˜๋ฏธ์„ ์‹œ์ž‘ํ•˜๊ธฐ ์œ„ํ•ด์„œ๋Š” ๊ฐ์ฒด๊ฐ€ ๊ฐ€์ง„..

    16. ๊ฐ’, ์ฐธ์กฐ์— ์˜ํ•œ ๋งค๊ฐœ๋ณ€์ˆ˜ ์ „๋‹ฌ, ref์™€ out์˜ ์ฐจ์ด

    ๊ฐ’์— ์˜ํ•œ ์ „๋‹ฌ์ด ๋งค๊ฐœ๋ณ€์ˆ˜๊ฐ€ ๋ณ€์ˆ˜๋‚˜ ์ƒ์ˆ˜๋กœ๋ถ€ํ„ฐ ๊ฐ’์„ ๋ณต์‚ฌํ•˜๋Š” ๊ฒƒ๊ณผ ๋‹ฌ๋ฆฌ, ์ฐธ์กฐ์— ์˜ํ•œ ์ „๋‹ฌ์€ ๋งค๊ฐœ๋ณ€์ˆ˜๊ฐ€ ๋ฉ”์†Œ๋“œ์— ๋„˜๊ฒจ์ง„ ์›๋ณธ ๋ณ€์ˆ˜๋ฅผ ์ง์ ‘ ์ฐธ์กฐํ•œ๋‹ค. using System; using System.Collections; using System.Collections.Generic; using System.Globalization; using System.Linq; using System.Text; using System.Threading.Tasks; using static System.Console; namespace Hello { class MainApp { public static void Swap(int a, int b) { int temp = b; b = a; a = temp; WriteLine($..

    15. ๋ฉ”์†Œ๋“œ๋กœ ์ฝ”๋“œ ๊ฐ„์ถ”๋ฆฌ๊ธฐ + ์žฌ๊ท€ํ˜ธ์ถœ ํ•จ์ˆ˜์งœ๊ธฐ(ํ”ผ๋ณด๋‚˜์น˜ ์˜ˆ์ œ)

    ๋ฉ”์†Œ๋“œ : ๊ฐ์ฒด์˜ ์ผ์„ ์ฒ˜๋ฆฌํ•˜๋Š” ๋ฐฉ๋ฒ• ๋˜๋Š” ๋ฐฉ์‹ C#์—์„œ๋Š” ๋ฌด์กฐ๊ฑด ํด๋ž˜์Šค ๋‚ด๋ถ€์— ์„ ์–ธํ•œ๋‹ค. ๋ฉ”์†Œ๋“œ๋Š” ์ฝ”๋“œ๋ฅผ ๊ฐ„์ถ”๋ฆฌ๋Š” ํ•œํŽธ, ์ฝ๊ธฐ ์‰ฝ๊ณ  ์ดํ•ดํ•˜๊ธฐ ์‰ฝ๊ฒŒ ๋งŒ๋“ ๋‹ค. ๊ฐ€๋ น ๋‹ค์Œ๊ณผ ๊ฐ™์€ ์ฝ”๋“œ๋ฅผ, using System; using System.Collections; using System.Collections.Generic; using System.Globalization; using System.Linq; using System.Text; using System.Threading.Tasks; using static System.Console; namespace Hello { class MainApp { static void Main(string[] args) { int a, b; a = 3; b = 4; Writ..

    14. ์ž…์ถœ๋ ฅ, ๋ถ„๊ธฐ๋ฌธ

    ์ปดํ“จํ„ฐ๊ฐ€ ์ดํ•ดํ•  ์ˆ˜ ์žˆ๋Š” ์ฝ”๋“œ๋Š” ์–ด๋А ๋ฐ”๋ณด๋‚˜ ๋‹ค ์งค ์ˆ˜ ์žˆ๋‹ค. ์ข‹์€ ํ”„๋กœ๊ทธ๋ž˜๋จธ๋Š” ์‚ฌ๋žŒ์ด ์ดํ•ดํ•  ์ˆ˜ ์žˆ๋Š” ์ฝ”๋“œ๋ฅผ ์ง ๋‹ค. -๋งˆํ‹ด ํŒŒ์šธ๋Ÿฌ using System; using System.Collections; using System.Collections.Generic; using System.Globalization; using System.Linq; using System.Text; using System.Threading.Tasks; using static System.Console; namespace Hello { class MainApp { static void Main(string[] args) { string str = ReadLine(); int number = Convert.ToInt32(str..

    13. null ๋ณ‘ํ•ฉ ์—ฐ์‚ฐ์ž

    a??b a๊ฐ€ null์ด๋ฉด b ๋ฐ˜ํ™˜ null์ด ์•„๋‹ˆ๋ฉด a ๊ทธ๋Œ€๋กœ ๋ฐ˜ํ™˜ null ๋ณ‘ํ•ฉ ์—ฐ์‚ฐ์ž ??๋Š” null ์กฐ๊ฑด๋ถ€ ์—ฐ์‚ฐ์ž์ฒ˜๋Ÿผ ํ”„๋กœ๊ทธ๋žจ์—์„œ ์ข…์ข… ํ•„์š”ํ•œ ๋ณ€์ˆ˜/๊ฐ์ฒด์˜ null ๊ฒ€์‚ฌ๋ฅผ ๊ฐ„๊ฒฐํ•˜๊ฒŒ ๋งŒ๋“ค์–ด์ค€๋‹ค. ?? ์—ฐ์‚ฐ์ž๋Š” ๋‘ ๊ฐœ์˜ ํ”ผ์—ฐ์‚ฐ์ž๋ฅผ ๋ฐ›์•„๋“ค์ด๊ณ  ์™ผ์ชฝ ํ”ผ์—ฐ์‚ฐ์ž๊ฐ€ null์ธ์ง€ ํ‰๊ฐ€ํ•œ๋‹ค. ํ‰๊ฐ€ ๊ฒฐ๊ณผ๊ฐ€ null์ด ์•„๋‹Œ ๊ฒƒ์œผ๋กœ ๋‚˜ํƒ€๋‚˜๋ฉด ํ”ผ์—ฐ์‚ฐ์ž๋ฅผ ๊ทธ๋Œ€๋กœ ๋ฐ˜ํ™˜ํ•˜๊ณ , null์ธ ๊ฒƒ์œผ๋กœ ํ‰๊ฐ€๋˜๋ฉด ์˜ค๋ฅธ์ชฝ ํ”ผ์—ฐ์‚ฐ์ž๋ฅผ ๋ฐ˜ํ™˜ํ•œ๋‹ค. using System; using System.Collections; using System.Collections.Generic; using System.Globalization; using System.Linq; using System.Text; using System.Threading.Task..

    12. ๋น„ํŠธ ์—ฐ์‚ฐ์ž

    12. ๋น„ํŠธ ์—ฐ์‚ฐ์ž

    ์ฐธ๊ณ ์˜์ƒ : https://youtu.be/VtqhZQP7T4c 1๋ฐ”์ดํŠธ๋Š” 8๋น„ํŠธ์ด๋‹ค. ๋ฐ์ดํ„ฐํ˜•์‹์˜ ํฌ๊ธฐ๋Š” ๋ชจ๋‘ '๋ฐ”์ดํŠธ'๋‹จ์œ„๋กœ ์ด๋ฃจ์–ด์ ธ ์žˆ๋‹ค. ๋น„ํŠธ ์ˆ˜์ค€์—์„œ ๋ฐ์ดํ„ฐ๋ฅผ ๊ฐ€๊ณตํ•ด์•ผ ํ•˜๋Š” ๊ฒฝ์šฐ๊ฐ€ ์ข…์ข… ์ƒ๊ธด๋‹ค. ๋น„ํŠธ ์—ฐ์‚ฐ์ž๋ฅผ ์ด๋ฅผ ์œ„ํ•œ ์—ฐ์‚ฐ์ž์ด๋‹ค. 1) ์‹œํ”„ํŠธ ์—ฐ์‚ฐ์ž : ๋น„ํŠธ๋ฅผ ์™ผ์ชฝ์ด๋‚˜ ์˜ค๋ฅธ์ชฝ์œผ๋กœ ์ด๋™์‹œํ‚ค๋Š” ์—ฐ์‚ฐ์ž ๋น„ํŠธ๋ฅผ ์ด๋™์‹œํ‚ฌ ๋•Œ๋Š” ๊ทœ์น™์ด ์žˆ๋‹ค. ๋ฐ€๋ ค์„œ ๋น ์ ธ๋‚˜์˜จ ๋น„ํŠธ๋Š” ๊ณผ๊ฐํ•˜๊ฒŒ ๋ฒ„๋ฆฐ๋‹ค. ์–‘์ˆ˜์— ๋Œ€ํ•œ ์‹œํ”„ํŠธ ์—ฐ์‚ฐ์ž๋Š” ๋น„๊ฒŒ๋œ ๋น„ํŠธ ๋งŒํผ 0์„ ์ฑ„์›Œ ๋„ฃ๋Š”๋‹ค. ์Œ์ˆ˜์— ๋Œ€ํ•œ ์‹œํ”„ํŠธ ์—ฐ์‚ฐ์ž๋Š” ๋น„๊ฒŒ๋œ ๋น„ํŠธ ๋งŒํผ 1์„ ์ฑ„์›Œ ๋„ฃ๋Š”๋‹ค. int a = 240; // 00000000 00000000 00001111 00000000 int resultl_1 = a 2; // 00000000 00000000 00000011 11000..

    11. null ์กฐ๊ฑด๋ถ€ ์—ฐ์‚ฐ์ž

    ๋„null ์กฐ๊ฑด๋ถ€ ์—ฐ์‚ฐ์ž ?.๋Š” C# 6.0์—์„œ ๋„์ž…๋˜์—ˆ๋‹ค. ?.๊ฐ€ ํ•˜๋Š” ์ผ์€ ๊ฐ์ฒด์˜ ๋ฉค๋ฒ„์— ์ ‘๊ทผํ•˜๊ธฐ ์ „์— ํ•ด๋‹น ๊ฐ์ฒด๊ฐ€ null์ธ์ง€ ๊ฒ€์‚ฌํ•˜์—ฌ ๊ทธ ๊ฒฐ๊ณผ๊ฐ€ ์ฐธ(์ฆ‰, ๊ฐ์ฒด๊ฐ€ null)์ด๋ฉด ๊ทธ ๊ฒฐ๊ณผ๋กœ null์„ ๋ฐ˜ํ™˜ํ•˜๊ณ , ๊ทธ๋ ‡์ง€ ์•Š์€ ๊ฒฝ์šฐ์—๋Š” . ๋’ค์— ์ง€์ •๋œ ๋ฉค๋ฒ„๋ฅผ ๋ฐ˜ํ™˜ํ•œ๋‹ค. ==์—ฐ์‚ฐ์ž๋ฅผ ์ด์šฉํ•œ ์ฝ”๋“œ ?. ์—ฐ์‚ฐ์ž๋ฅผ ์ด์šฉํ•œ ์ฝ”๋“œ class Foo { public int member; } Foo foo = null; int?bar; if(foo==null) bar = null; else bar = foo.member; class Foo { public int member; } Foo foo = null; int? bar; bar = foo?.member; //foo ๊ฐ์ฒด๊ฐ€ null์ด ์•„๋‹ˆ๋ฉด member ํ•„๋“œ์— ์ ‘๊ทผ..