That's simply impossible in the current C# syntax (no matter how eager you want it), as even for built-in classes such as SqlConnection
you can feel free to create new instances without using
.
The philosophy since C# 1.0 in 2000 you should adapt to is that instead of forcing the users to remember using
, you should allow them to forget that. To avoid memory leak, follow the standard IDisposable
pattern to properly implement the Dispose
method and finalizer.
If this is your time to hear the concept of finalization, you need to read more from key articles like