We have learned in the previous section that object disposal in .NET Core is automatically done by the GC. Nevertheless, disposing of objects in your code is always a good practice, and is highly recommended when you are working with unmanaged objects. In this section, we will explore some best practices that can be used to dispose of objects while writing code in .NET Core.
Best practices for disposing of objects in .NET Core
Introduction to the IDisposable interface
IDisposable is a simple interface that contains one Dispose method, takes no parameter, and returns void:
public interface IDisposable { void Dispose(); }
It is used to release unmanaged resources. So if any class implements the IDisposable interface, it...