HOW TO USE IDISPOSABLE INTERFACE IN C#.

Ankit Singh

Total Post:341

Points:2389
Posted by  Ankit Singh
C# 
C#
 416  View(s)
Ratings:
Rate this:
I want to use IDisposable Interface In c#. How to use this Please help me.
  1. aditya kumar Patel

    Post:254

    Points:1810
    Re: How to use IDisposable Interface In c#.


    IDisposable interface is to release unmanaged resources.
    It automatically destroy unused objects free up the memory.
    for more information goto
    https://msdn.microsoft.com/en-us/library/system.idisposable(v=vs.110).aspx

    using System;
    using System.Collections;
    using System.Collections.Generic;
    using System.Data;
    using System.Diagnostics;
    using System.IO;

    public class disposable
    {
    public static void Main()
    {
    Class1 obj=new Class1 ();
    obj.insertvalues("Rajendra Kumar ",25);
    obj.Dispose();
    Console.WriteLine("Press Return to collect the garbage...");
    GC.Collect();
    Console.WriteLine("Press Return to quit...");
    Console.ReadLine();
    }
    }

    public class Class1 : IDisposable
    {

    public void insertvalues(string name, int age)
    {
    Console.WriteLine(name);
    Console.WriteLine(age);
    Console.WriteLine("Object " + GetHashCode() + " disposed.");
    }

    public void Dispose()
    {
    GC.SuppressFinalize(this);
    Console.WriteLine("Object " + GetHashCode() + " disposed.");
    }
    }

     

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!