c# dispose method code example
Example 1: dispose method in c# with example
public sealed class Foo : IDisposable
{
private readonly IDisposable _bar;
public Foo()
{
_bar = new Bar();
}
public void Dispose()
{
_bar?.Dispose();
}
}
Example 2: dispose method in c# with example
using System;
class DerivedClass : BaseClass
{
bool _disposed = false;
~DerivedClass() => Dispose(false);
protected override void Dispose(bool disposing)
{
if (_disposed)
{
return;
}
if (disposing)
{
}
_disposed = true;
base.Dispose(disposing);
}
}