CKTIS / C#
using: odniesienie praktyczne
using: odniesienie praktyczne: using importuje namespace/alias albo deterministycznie zwalnia IDisposable.
Wersja: C# language; verified against C# 14 reference
Składnia
using /* grammar-specific form */using importuje namespace/alias albo deterministycznie zwalnia IDisposable.
Stosuj deklarację using natychmiast po przejęciu zasobu.
Import może powodować konflikty nazw; using resource nie obsługuje IAsyncDisposable bez await.
Dispose wykonuje się przy wyjściu ze scope, również przez return lub wyjątek.
Kompletny program rzeczywiście używa using; oczekiwany stdout to dokładnie line.
Przykłady
using System;
using System.Buffers;
using System.Collections.Concurrent;
using System.Collections.Frozen;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Text;
using System.Text.Json;
using System.Text.Json.Nodes;
using System.Text.Json.Serialization;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Channels;
using System.Threading.Tasks;
using Number = System.Int32;
using var reader = new StringReader("line"); Console.WriteLine(reader.ReadLine());
Wynik
line
Kompletny program rzeczywiście używa `using`; oczekiwany stdout to dokładnie `line`.