C#模拟D的区间.
using System;
#nullable enable
// ensure this is a stack only struct
ref struct ScopeExit {
public ScopeExit(Action cleaner)
{
this.cleaner = cleaner;
}
public void Dispose()
{
try
{
cleaner();
}
catch {
// maybe do something interesting here
}
}
private Action cleaner;
}
public class Example {
public static void Main() {
using var netSocket = new ScopeExit(() => { /* clean somethig */});
}
}
浙公网安备 33010602011771号