728x90

๐ŸŽฎ Unity Study/C# 19

[C#] using ๋ฌธ

* using ๊ตฌ๋ฌธ: IDisponsable ๊ฐ์ฒด์˜ ์˜ฌ๋ฐ”๋ฅธ ์‚ฌ์šฉ์„ ๋ณด์žฅํ•˜๋Š” ๊ตฌ๋ฌธ. ๋ฉ”๋ชจ๋ฆฌ ๊ด€๋ฆฌ File๋‚˜ Font ๊ฐ™์€ ๊ด€๋ฆฌ๋˜์ง€ ์•Š๋Š” ๋ฆฌ์†Œ์Šค์— ์ ‘๊ทผํ•˜๋Š” ํด๋ž˜์Šค๋“ค์€ ์‚ฌ์šฉ ํ›„์— ๋ฐ˜๋“œ์‹œ ํ•ด์ œ(Disponse) ํ•ด์•ผ ํ•œ๋‹ค. using ๊ตฌ๋ฌธ ์•ˆ์—์„œ ์‚ฌ์šฉํ•˜๋ฉด ๊ฐœ๋ฐœ์ž๊ฐ€ ์ง์ ‘ ์ฒดํฌํ•ด์„œ Disponse ํ•˜์ง€ ์•Š์•„๋„ ๋œ๋‹ค. using ๋ฌธ์„ ๋ฒ—์–ด๋‚˜๋ฉด ์ž๋™์œผ๋กœ ํ•ด์ œ(Disponse) ๋˜์–ด ๊ด€๋ฆฌ๋ฅผ ๋„์™€์ค€๋‹ค. * ์˜ˆ์‹œ var numbers = new List(); using (StreamReader reader = File.OpenText("numbers.txt")) { string line; while ((line = reader.ReadLine()) is not null) { if (int.TryParse(line, out ..

[Unity][๋””์ž์ธ ํŒจํ„ด] Builder Pattern(๋นŒ๋” ํŒจํ„ด)

* Builder Pattern: ๊ฐ์ฒด๋ฅผ ์ƒ์„ฑํ•  ๋•Œ ๊ทธ ๊ฐ์ฒด๋ฅผ ๊ตฌ์„ฑํ•˜๋Š” ๋ถ€๋ถ„ ๋ถ€๋ถ„์„ ๋จผ์ € ์ƒ์„ฑํ•˜๊ณ , ์ด๋ฅผ ์กฐํ•ฉํ•จ์œผ๋กœ์จ ๊ฐ์ฒด ์ „์ฒด๋ฅผ ์ƒ์„ฑํ•œ๋‹ค. * Builder Pattern ๊ณผ Abstract Factroy Pattern ๊ณผ์˜ ์ฐจ์ด์  1) Builder Pattern: ๋ณต์žกํ•œ ๊ฐ์ฒด์˜ ๋‹จ๊ณ„๋ณ„ ์ƒ์„ฑ์— ์ค‘์ ์„ ๋‘๊ณ  ์žˆ๋Š” ํŒจํ„ด. ๋งˆ์ง€๋ง‰ ๋‹จ๊ณ„์—์„œ ์ƒ์„ฑํ•œ ์ œํ’ˆ๋ฐ˜ํ™˜. 2) Abstract Factroy Pattern: ์ œํ’ˆ์˜ ์œ ์‚ฌ๊ตฐ๋“ค์ด ์กด์žฌํ•˜๋Š” ๊ฒฝ์šฐ ์œ ์—ฐํ•œ ์„ค๊ณ„์— ์ค‘์ ์„ ๋‘๋Š” ํŒจํ„ด. ๋‹จ๊ณ„๋งˆ๋‹ค ๋งŒ๋“œ๋Š” ์ œํ’ˆ์„ ์ฆ‰์‹œ ๋ฐ˜ํ™˜. Vehicle(Car, MotorCycle) ๊ฐ์ฒด๋ฅผ ๋งŒ๋“œ๋Š” Builder ํŒจํ„ด์„ ๊ตฌํ˜„ํ•ด๋ณด์ž. ํƒˆ ๊ฒƒ์˜ ๊ณตํ†ต ๋ณ€์ˆ˜์™€ ๊ธฐ๋Šฅ์„ ๊ฐ–๊ณ  ์žˆ๋Š” Vehicle ํด๋ž˜์Šค์™€ Vehicle ์„ ์ง์ ‘ ๋งŒ๋“œ๋Š” ๋ฐ ํ•„์š”ํ•œ In..

[C#] Boxing, Unboxing -> Generic

https://learn.microsoft.com/ko-kr/dotnet/csharp/programming-guide/types/boxing-and-unboxing Boxing ๋ฐ Unboxing - C# ํ”„๋กœ๊ทธ๋ž˜๋ฐ ๊ฐ€์ด๋“œ - C# C# ํ”„๋กœ๊ทธ๋ž˜๋ฐ์˜ boxing ๋ฐ unboxing์— ๋Œ€ํ•ด ์•Œ์•„๋ด…๋‹ˆ๋‹ค. ์ฝ”๋“œ ์˜ˆ์ œ๋ฅผ ์‚ดํŽด๋ณด๊ณ  ์‚ฌ์šฉ ๊ฐ€๋Šฅํ•œ ์ถ”๊ฐ€ ๋ฆฌ์†Œ์Šค๋ฅผ ํ™•์ธํ•ฉ๋‹ˆ๋‹ค. learn.microsoft.com https://yeko90.tistory.com/entry/c-%EB%B0%95%EC%8B%B1-%EC%96%B8%EB%B0%95%EC%8B%B1-%EA%B0%9C%EB%85%90 [c#] ๋ฐ•์‹ฑ(boxing), ์–ธ๋ฐ•์‹ฑ(unboxing) ๊ฐœ๋…๊ณผ ์‚ฌ์šฉ ์ด์œ  ๊ธฐ์กด์— ํƒ€์ž…์„ ๋ณ€ํ™˜ํ•˜๋Š”๊ฒƒ์„ ํ˜•๋ณ€ํ™˜(type casting)์ด..

C# & Unity Code Convention

Unity ์—์„œ Microsoft์™€ Google์˜ C# Code Convention์„ ๊ธฐ๋ฐ˜์œผ๋กœ Unity ๊ถŒ์žฅ Coding ๊ทœ์น™์„ ์ •๋ฆฌํ•ด์ค€ ๋ฌธ์„œ๋ฅผ ์ œ๊ณตํ•œ๋‹ค. Create a C# style guide: Write cleaner code that scales Get tips from industry experts on how to create a C# code style guide. A style guide can help your team develop a codebase to support the growth of your project to a commercial-scale production. resources.unity.com ์•„๋ž˜ ๋งํฌ์—์„œ ๋ฒˆ์—ญ์ค‘ ~ C# Coding Convention C# C..

[C#] ๋ฌธ๋ฒ• Keyword

? readonly : ์ธ์ŠคํŽ™ํ„ฐ์ฐฝ์—์„œ ์ˆ˜์ •ํ•  ์ˆ˜ ์—†๋Š” ๋ณ€์ˆ˜๋ฅผ ์˜๋ฏธํ•จ. sealed : ๋ด‰์ธ๋œ. ๋”์ด์ƒ ์ƒ์†์ด ๋ถˆ๊ฐ€๋Šฅํ•œ ํด๋ž˜์Šค/์†์„ฑ/ํ•จ์ˆ˜๋ฅผ ์˜๋ฏธํ•จ. : ์ƒ์†, ์ธํ„ฐํŽ˜์ด์Šค ๋“ฑ์œผ๋กœ ํด๋ž˜์Šค ๊ตฌ์กฐ๊ฐ€ ๋ณต์žกํ•ด์งˆ ๋•Œ ์ƒ์†์˜ ๊นŠ์ด๋ฅผ ์ œํ•œํ•˜๊ธฐ ์œ„ํ•ด ๋‹ค๋ฅธ์‚ฌ๋žŒ์—๊ฒŒ ์ด ํด๋ž˜์Šค, ์†์„ฑ, ํ•จ์ˆ˜๋Š” ์ƒ์†์ด ์•ˆ๋œ๋‹ค๊ณ  ๋ช…์‹œํ•˜๊ธฐ ์œ„ํ•ด ์‚ฌ์šฉ. public class LoginInterface() { } public sealed class LoginImplementation { } partial static 1) static ๋ฉ”์„œ๋“œ : ํด๋ž˜์Šค๋กœ๋ถ€ํ„ฐ ๊ฐ์ฒด๋ฅผ ์ƒ์„ฑํ•˜์ง€ ์•Š๊ณ  'ํด๋ž˜์Šค๋ช….๋ฉ”์„œ๋“œ๋ช…'์œผ๋กœ ๋ฐ”๋กœ ํ˜ธ์ถœํ•˜๋Š” ๋ฉ”์„œ๋“œ. 2) static ์†์„ฑ, ํ•„๋“œ : ํด๋ž˜์Šค๋กœ๋ถ€ํ„ฐ ๊ฐ์ฒด๋ฅผ ์ƒ์„ฑํ•˜์ง€ ์•Š๊ณ  'ํด๋ž˜์Šค๋ช….์†์„ฑ๋ช…'์œผ๋กœ ๋ฐ”๋กœ ํ˜ธ์ถœํ•จ. : non-static..

[C#][์ƒ์†๊ณผ ์ธํ„ฐํŽ˜์ด์Šค] virtual, abstract, interface

์ƒ์†๊ณผ ํด๋ž˜์Šค ์„ค๊ณ„ ์‹œ ํ”ํžˆ ์‚ฌ์šฉํ•˜๋Š” virtual, abstract, interface ๊ฐ€ ๋ฌด์—‡์ธ์ง€, ๋ฌด์Šจ ์ฐจ์ด๊ฐ€ ์žˆ๋Š”์ง€ ์•Œ์•„๋ณด์ž virtual (ํ•จ์ˆ˜, ์†์„ฑ, ์ธ๋ฑ์„œ, ์ด๋ฒคํŠธ) : ํŒŒ์ƒ ํด๋ž˜์Šค์—๊ฒŒ ์ƒ์†์œผ๋กœ ์™„๋ฒฝํ•œ ๊ธฐ๋Šฅ์„ ์ œ๊ณตํ•˜๋Š” ๊ฒƒ. public class Animal(){ public virtual void Speak(){ Console.WriteLine(""); } } public class Dog : Animal(){ public override void Speak(){ Console.WriteLine("๋ฉ๋ฉ"); } } Dog maltize = new Dog(); maltize.Speak(); virtual ํ•œ์ •์ž๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ํ•จ์ˆ˜๋Š” ํŒŒ์ƒ ํด๋ž˜์Šค์—๊ฒŒ ์™„๋ฒฝํ•œ ๊ธฐ๋Šฅ์„ ์ œ๊ณตํ•  ์ˆ˜ ์žˆ๋‹ค. ํŒŒ์ƒ ํด๋ž˜์Šค์—..

[C#] ? Question Mark

C# 6.0 ๋ถ€ํ„ฐ Null ์ฒดํฌ ์—ฐ์‚ฐ์ž ? ์™€ ?? ๊ฐ€ ์ถ”๊ฐ€ ๋˜์—ˆ๋”ฐ. ๊ทธ๋ž˜์„œ ์•„๋ž˜ ์ฝ”๋“œ๋Š” ๊ฐ™์€ ์˜๋ฏธ์ด๋‹ค. if(current == null){ current = gameObject; } current.Start(); current?.Start(); ๋˜ํ•œ C# 8.0 ๋ถ€ํ„ฐ ๋„ ํ• ๋‹น์ž ??= ๋„ ์ถ”๊ฐ€๋˜์—ˆ๋‹ค.

[C#] C# ๋ฒ„์ „๋ณ„ ์ถ”๊ฐ€๊ธฐ๋Šฅ ์‚ฌํ•ญ, .NET & Visual Studio ๋ฒ„์ „

ํ˜„์žฌ C# ๋ฒ„์ „์€ 11 (2022๋…„ 11์›” release) ๊นŒ์ง€ ์—…๋ฐ์ดํŠธ ๋˜์—ˆ๋‹ค. ๊ทธ๋ฆฌ๊ณ  C#์€ .NET Framwork ๋ฒ„์ „๊ณผ Visual Studio ๋ฒ„์ „์ด ๋ฐ€์ ‘ํ•œ ๊ด€๋ จ์ด ์žˆ๋‹ค. [Target๋ฒ„์ „C# ์–ธ์–ด ๋ฒ„์ „ ๊ธฐ๋ณธ๊ฐ’] Target .NET Version Visual Studio Version C# ์–ธ์–ด Version ๊ธฐ๋ณธ๊ฐ’ .NET 7.x VS 2022 C# 11 .NET 6.x VS 2017 C# 10 .NET 5.x VS 2019 16.8 C# 9.0 .NET Core 3.x VS 2019 16.3 C# 8.0 .NET Standard 2.0 VS 2017 C# 7.3 .NET Standard 1.x VS 2017 C# 7.3 .NET Framework ๋ชจ๋‘ VS 2017 C# 7.3 ์ฆ‰ C# ..

728x90