KO CSharp Keyword using - LIHACHTETAN/ClassicUO-Bad-Newbie-CSharp-Scripts-IDE GitHub Wiki

ะฃะบั€ะฐั—ะฝััŒะบะฐ ยท ะ ัƒััะบะธะน ยท English ยท Deutsch ยท Franรงais ยท Italiano ยท Espaรฑol ยท ็น้ซ”ไธญๆ–‡ ยท ๆ—ฅๆœฌ่ชž ยท ํ•œ๊ตญ์–ด

C#: using

ํ•ธ๋“œ๋ถ C# ยท ์‹ค์šฉ ๊ฐ€์ด๋“œ

์ด๋ฆ„์„ ๊ฐ€์ ธ์˜ค๊ฑฐ๋‚˜ ๋ณ„์นญ์„ ์„ค์ •ํ•˜๊ฑฐ๋‚˜ IDisposable/IAsyncDisposable ๋ฆฌ์†Œ์Šค๋ฅผ ๊ด€๋ฆฌํ•ฉ๋‹ˆ๋‹ค. ๊ฐ€์ ธ์˜ค๊ธฐ ์ž์ฒด๋Š” ๋ˆ„๋ฝ๋œ ์ข…์†์„ฑ์„ ์ถ”๊ฐ€ํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค.

๊ฐ„๋‹จํ•œ ์˜ˆ์ œ (Example.cs)

์ด ์˜ˆ์ œ๋ฅผ Example.cs๋กœ ๋”ฐ๋กœ ์ €์žฅํ•˜๊ณ  ์ด ํŽ˜์ด์ง€์˜ ๋‹ค๋ฅธ ์˜ˆ์ œ์™€ ๋…๋ฆฝ์ ์œผ๋กœ ์‹คํ–‰ํ•˜์„ธ์š”.

Example.cs:

// PROJECT-EXAMPLE
using System;
using (var stream = new System.IO.MemoryStream())
{
    stream.WriteByte(65);
    Console.WriteLine(stream.Length);
}

๊ฒฐ๊ณผ:

1

ํ†ต์‚ฌ๋ก 

using Namespace; / using Alias = Type; / using var resource = ...; / await using ...;

using ์„ ์–ธ์€ ๋ฒ”์œ„๊ฐ€ ๋๋‚  ๋•Œ๊นŒ์ง€ ์œ ํšจํ•ฉ๋‹ˆ๋‹ค. .csx์˜ ๊ฒฝ์šฐ ์ตœ์ƒ์œ„ ์„ ์–ธ์ด ์Šคํฌ๋ฆฝํŠธ ๊ตฌ๋ฌธ์— ๋Œ€ํ•ด ๋ชจํ˜ธํ•œ ๊ฒฝ์šฐ using (...) { ... }๋ฅผ ์‚ฌ์šฉํ•˜์„ธ์š”.

์˜ˆ์‹œ 1: ๊ธฐ๋ณธ ํ˜•ํƒœ

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using System.IO;
using System.Runtime.InteropServices;
using System.Runtime.CompilerServices;

public static class Program
{
    public static async Task Main(string[] args)
    {
        using var stream = new MemoryStream();
        stream.WriteByte(65);
        Console.WriteLine(stream.Length);
    }
}

์˜ˆ 2: ๋˜ ๋‹ค๋ฅธ ์‹ค์ œ ํ˜•์‹

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using System.IO;
using System.Runtime.InteropServices;
using System.Runtime.CompilerServices;

public static class Program
{
    public static async Task Main(string[] args)
    {
        await using var stream = new MemoryStream();
        await stream.WriteAsync(new byte[] { 1, 2, 3 });
        Console.WriteLine(stream.Length);
    }
}

๊ณต์‹ ์ถœ์ฒ˜: Microsoft ํ•™์Šต.