Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

IDisposable Interface

$
0
0
    class Item:IDisposable
    {
         int id;
         string Description;
         int price;
       

        public Item()
        {
            id = 0;
            Description = "";
            price = 0;
        }




        public void Dispose()
        {
            Dispose(true);
            //Garbage collector
            GC.SuppressFinalize(this);
           
        }

        protected virtual void Dispose(bool disposing)
        {
            if (disposing)
            {
                // how to release resources ?
            }
        }

       
    }


This is my code

 using (Item i = new Item())
            {


            }


when the execution finish it should call to Dispose() method
Why use another method

 protected virtual void Dispose(bool disposing)


like this

 protected virtual void Dispose(bool disposing)
        {
            if (disposing)
            {
                // how to release resources ?
            }
        }


any way what is release resources ?
in my case how do i release my resources ?

Thank you very much

Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>