C#でdefer
IDisposableとusingで再現。
public class ScopedDefer : IDisposable
{
private readonly Action action;
public ScopedDefer(Action action)
{
this.action = action;
}
public void Dispose()
{
action();
}
}
使い方
stack++;
using var _ = new ScopedDefer(() => stack--);