๐ŸŽฎ Unity Study/C#

[C#] using ๋ฌธ

ibelieveinme 2023. 12. 13. 16:42
728x90

* using ๊ตฌ๋ฌธ: IDisponsable ๊ฐ์ฒด์˜ ์˜ฌ๋ฐ”๋ฅธ ์‚ฌ์šฉ์„ ๋ณด์žฅํ•˜๋Š” ๊ตฌ๋ฌธ. ๋ฉ”๋ชจ๋ฆฌ ๊ด€๋ฆฌ

 

File๋‚˜ Font ๊ฐ™์€ ๊ด€๋ฆฌ๋˜์ง€ ์•Š๋Š” ๋ฆฌ์†Œ์Šค์— ์ ‘๊ทผํ•˜๋Š” ํด๋ž˜์Šค๋“ค์€ ์‚ฌ์šฉ ํ›„์— ๋ฐ˜๋“œ์‹œ ํ•ด์ œ(Disponse) ํ•ด์•ผ ํ•œ๋‹ค.

using ๊ตฌ๋ฌธ ์•ˆ์—์„œ ์‚ฌ์šฉํ•˜๋ฉด ๊ฐœ๋ฐœ์ž๊ฐ€ ์ง์ ‘ ์ฒดํฌํ•ด์„œ Disponse ํ•˜์ง€ ์•Š์•„๋„ ๋œ๋‹ค. using ๋ฌธ์„ ๋ฒ—์–ด๋‚˜๋ฉด ์ž๋™์œผ๋กœ ํ•ด์ œ(Disponse) ๋˜์–ด ๊ด€๋ฆฌ๋ฅผ ๋„์™€์ค€๋‹ค.

 

 

* ์˜ˆ์‹œ

var numbers = new List<int>();
using (StreamReader reader = File.OpenText("numbers.txt"))
{
    string line;
    while ((line = reader.ReadLine()) is not null)
    {
        if (int.TryParse(line, out int number))
        {
            numbers.Add(number);
        }
    }
}

 

 

* ์ฐธ๊ณ 

https://learn.microsoft.com/ko-kr/dotnet/csharp/language-reference/statements/using

 

using ๋ฌธ - ์‚ญ์ œ ๊ฐ€๋Šฅํ•œ ๊ฐœ์ฒด์˜ ์˜ฌ๋ฐ”๋ฅธ ์‚ฌ์šฉ ํ™•์ธ - C#

C#using ๋ฌธ ๋˜๋Š” ์„ ์–ธ์„ ์‚ฌ์šฉํ•˜์—ฌ ์‚ญ์ œ ๊ฐ€๋Šฅํ•œ ๊ฐœ์ฒด์˜ ์˜ฌ๋ฐ”๋ฅธ ์‚ฌ์šฉ์„ ๋ณด์žฅํ•ฉ๋‹ˆ๋‹ค.

learn.microsoft.com

 

728x90

'๐ŸŽฎ Unity Study > C#' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๋‹ค๋ฅธ ๊ธ€

[Unity][๋””์ž์ธ ํŒจํ„ด] Builder Pattern(๋นŒ๋” ํŒจํ„ด)  (0) 2023.09.21
[C#] Boxing, Unboxing -> Generic  (0) 2023.09.08
C# & Unity Code Convention  (0) 2023.08.29
[C#] Generic, Template  (0) 2023.08.21
[C#] ๋ฌธ๋ฒ• Keyword  (0) 2023.08.19