CKTIS / C#
finally: практическа справка
finally: практическа справка: finally извършва cleanup след нормален изход или изключение от try.
Версия: C# language; verified against C# 14 reference
Синтаксис
finally /* grammar-specific form */finally извършва cleanup след нормален изход или изключение от try.
Използвайте за детерминистично освобождаване, когато using не е достатъчен.
Изключение от finally може да скрие първоначалното изключение.
Може да не се изпълни при рязко спиране; return в try все пак минава през finally.
Пълната програма действително използва finally; точният очакван stdout е try\nfinally.
Примери
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;
try { Console.WriteLine("try"); } finally { Console.WriteLine("finally"); }
Резултат
try finally
Пълната програма действително използва `finally`; точният очакван stdout е `try\nfinally`.