Consider a disposable with side effects in the constructor:
public class MyDisposable : IDisposable
{
public MyDisposable()
{
// Some side effects
...
}
public void Dispose()
{
...
}
}
If I'm only interested in the side effects I can, in some method, use the class like so:
using var _ = new MyDisposable();
using var __ = new MyDisposable();
using var ___ = new MyDisposable();
Is there some syntax to avoid declaring the variables as they are unused? Something like:
using new MyDisposable();
using new MyDisposable();
using new MyDisposable();
I'm only interested in if there is such a syntax. I'm not looking for a way to restructure the code into a more sane approach.
new MyDisposable().Dispose();?using (new MyDisposable()) {}public MyDisposable() { Monitor.Enter(o); } public void Dispose(){ Monitor.Exit(o); }That may come in useful in one form or another.