์ ์ฒด ๊ธ
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. ๋นํธ ์ฐ์ฐ์
์ฐธ๊ณ ์์ : 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 ํ๋์ ์ ๊ทผ..