Simple IDisposable pattern : IDisposable « Class « C# / CSharp Tutorial






using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Text;
using System.Security.Cryptography;

class MyClass : IDisposable
{
    private Stream myStream = null;

    public void Dispose()
    {
        Stream s = myStream;
        if (s != null)
            ((IDisposable)s).Dispose();
    }
}

public class MainClass
{
    public static void Main()
    {
        using (MyClass mc = new MyClass())
        {
        }
    }

}








7.54.IDisposable
7.54.1.Simple IDisposable pattern
7.54.2.implementation of IDisposable
7.54.3.Complex IDisposable pattern