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]์ •์  ํ•„๋“œ์™€ ์ •์  ๋ฉ”์†Œ๋“œ

    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. ๋น„ํŠธ ์—ฐ์‚ฐ์ž

    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..