C#
21. this, this() ์์ฑ์
"๋", "์ ๋" ... ์๊ธฐ ์์ ์ ์ง์นญํ ๋ "๋"๋ผ๊ณ ํ๋ค. this๋ ๊ฐ์ฒด๊ฐ ์์ ์ ์ง์นญํ ๋ ์ฌ์ฉํ๋ ํค์๋์ด๋ค. ๊ทธ๋ฌ๋๊น, ๊ฐ์ฒด ์ธ๋ถ์์๋ ๊ฐ์ฒด์ ํ๋๋ ๋ฉ์๋์ ์ ๊ทผํ ๋ ๊ฐ์ฒด์ ์ด๋ฆ(๋ณ์ ๋๋ ์๋ณ์)๋ฅผ ์ฌ์ฉํ๋ค๋ฉด, ๊ฐ์ฒด ๋ด๋ถ์์๋ ์์ ์ ํ๋๋ ๋ฉ์๋์ ์ ๊ทผํ ๋ this ํค์๋๋ฅผ ์ฌ์ฉํ๋ค. this๊ฐ ๊ฐ์ฒด ์์ ์ ์ง์นญํ๋ ํค์๋์ธ ๊ฒ์ฒ๋ผ, this()๋ ์๊ธฐ ์์ ์ ์์ฑ์๋ฅผ ์นด๋ฆฌํจ๋ค. this()๋ ์์ฑ์์์๋ง ์ฌ์ฉ๋ ์ ์๋ค. using System; using System.Collections; using System.Collections.Generic; using System.Globalization; using System.Linq; using System.Text; using ..
20. ์์ ๋ณต์ฌ(Shallow Copy)์ ๊น์ ๋ณต์ฌ(Deep Copy)
ํด๋์ค๋ ํ์์ด ์ฐธ์กฐ ํ์์ด๋ค. ์ฐธ์กฐ ํ์์ ํ ์์ญ์ ๊ฐ์ฒด๋ฅผ ํ ๋นํ๊ณ , ์คํ์ ์๋ ์ฐธ์กฐ๊ฐ ํ ์์ญ์ ํ ๋น๋ ๋ฉ๋ชจ๋ฆฌ๋ฅผ ๊ฐ๋ฆฌํจ๋ค. 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 UsingOut { class MyClass { public int MyField1; public int MyField2; } class MainApp { static void Main(string[] arg..
![19. [static]์ ์ ํ๋์ ์ ์ ๋ฉ์๋](https://img1.daumcdn.net/thumb/R750x0/?scode=mtistory2&fname=https%3A%2F%2Fblog.kakaocdn.net%2Fdna%2FcaA02p%2FbtrsYdxWivZ%2FAAAAAAAAAAAAAAAAAAAAAKXDzYlcroqKmB28XAbF9ljR1qctSs8q_lAzgJWqWLPK%2Fimg.png%3Fcredential%3DyqXZFxpELC7KVnFOS48ylbz2pIh7yKj8%26expires%3D1756652399%26allow_ip%3D%26allow_referer%3D%26signature%3DQ417Kp5a1%252B6x8p6Wf4TKpvv1SYw%253D)
19. [static]์ ์ ํ๋์ ์ ์ ๋ฉ์๋
static์ ์ฌ์ ์ ์ผ๋ก '์ ์ '์ด๋ผ๋ ๋ป์ ๊ฐ์ง๊ณ ์๋ค.(์์ง์ด์ง ์๋๋ค.) C#์์ static์ ๋ฉ์๋๋ ํ๋๊ฐ ํด๋์ค์ ์ธ์คํด์ค๊ฐ ์๋ ํด๋์ค ์์ฒด์ ์์๋๋๋ก ์ง์ ํ๋ ํ์ ์์ด๋ค. ํ ํ๋ก๊ทธ๋จ ์์์ ์ธ์คํด์ค๋ ์ฌ๋ฌ ๊ฐ๊ฐ ์กด์ฌํ ์ ์์ผ๋ ํด๋์ค๋ ๋จ ํ๋๋ง ์กด์ฌํ๋ค. ๋๊ฐ์ ํด๋์ค๊ฐ ๋ ๊ฐ ์ด์ ์กด์ฌํ ์๋ ์๋ค. ์ด๋ค ํ๋๊ฐ ํด๋์ค์ ์์๋๋ค๋ ๊ฒ์ ๊ณง ๊ทธ ํ๋๊ฐ ํ๋ก๊ทธ๋จ ์ ์ฒด์์ ์ ์ผํ๊ฒ ์กด์ฌํ๋ค๋ ๊ฒ์ ์๋ฏธํ๋ค. ๋ค์ ํ๋ ํ๋(ํด๋์ค ์์ ์ ์ธํ ๋ณ์)๊ฐ ์ธ์คํด์ค์ ์์๋ ๊ฒฝ์ฐ์ ํด๋์ค์ ์์๋ ๊ฒฝ์ฐ์ ์์ ์ฝ๋๋ฅผ ๋ด๊ณ ์๋ค. static์ผ๋ก ํ์ ํ์ง ์์ ํ๋๋ ์๋์ผ๋ก ์ธ์คํด์ค์ ์์๋๋ฉฐ, static์ผ๋ก ํ์ ํ ํ๋๋ ํด๋์ค์ ์์๋๋ค. ์ ์ ํ๋๋ฅผ ๋ง๋ค์ด์ ์ป๋ ์ด๋: stati..
18. ๊ฐ์ฒด์ ์ถ๊ณผ ์ฃฝ์(์์ฑ์,์ข ๋ฃ์) + ์์ฑ์ ์ค๋ฒ๋ก๋ฉ
๊ฐ์ฒด๊ฐ ์์ฑ๋ ๋๋ ์์ฑ์๊ฐ ํธ์ถ๋๊ณ ์๋ฉธํ ๋๋ ์ข ๋ฃ์๊ฐ ํธ์ถ๋๋ค. ์์ฑ์๋ ํด๋์ค์ ์ด๋ฆ์ด ๊ฐ๊ณ ๋ฐํ ํ์์ด ์๋ค. ์์ฑ์์ ์๋ฌด๋ ํด๋น ํ์(ํด๋์ค)์ ๊ฐ์ฒด๋ฅผ ์์ฑํ๋ ๊ฒ ๋ฟ์ด๊ธฐ ๋๋ฌธ์ด๋ค. 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 UsingOut { class Cat { public Cat() { } } class MainApp { static void Main(strin..
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..