Repository navigation
JA CSharp Keyword using
Codex edited this page Oct 11, 2026
·
2 revisions
Українська · Русский · English · Deutsch · Français · Italiano · Español · 繁體中文 · 日本語 · 한국어
名前のインポート、エイリアスの設定、または IDisposable/IAsyncDisposable リソースの管理を行います。インポート自体は、不足している依存関係を追加しません。
この例を 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 (...) { ... } を使用します。
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);
}
}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 Learn。
ClassicUO — Bad Newbie & C# Scripts IDE