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 ํ์ต.