Home > DeveloperSection > Forums > How to use IDisposable Interface In c#.
Ankit Singh

Total Post:341

Points:2389
Posted on    January-07-2016 11:11 PM

 C# C# 
Ratings:


 1 Reply(s)
 228  View(s)
Rate this:
I want to use IDisposable Interface In c#. How to use this Please help me.


aditya kumar Patel

Total Post:246

Points:1752
Posted on    January-07-2016 11:21 PM


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.");
}
}

 


Don't want to miss updates? Please click the below button!

Follow MindStick