Disposes all members implementing IDisposable. - CSharp System

CSharp examples for System:IDisposable

Description

Disposes all members implementing IDisposable.

Demo Code


using System.Text;
using System.Linq;
using System.Collections.Generic;
using System.Collections;
using System;/*  w ww  .j ava 2 s  .  co m*/

public class Main{
        /// <summary>
        /// Disposes all members implementing <see cref="IDisposable"/>.
        /// </summary>
        /// <param name="list">List of items to dispose.</param>
        public static void Dispose(this IList list)
        {
            foreach (var disposable in list.Cast<IDisposable>().ToArray())
            {
                list.Remove(disposable);
                disposable.Dispose();
            }
        }
}

Related Tutorials