Код: Выделить всё
using System;
struct X(string name) : IDisposable
{
public void Dispose()
{
Console.WriteLine(name);
}
}
public class Program
{
public static void func()
{
using var x4 = new X("4");
using var x3 = new X("3");
Console.WriteLine("2");
}
public static void Main()
{
Console.WriteLine("1");
func();
Console.WriteLine("5");
}
}
Подробнее здесь: https://stackoverflow.com/questions/796 ... d-of-scope