Re: Implementing IDisposible for my Class
- From: "Andrew Faust" <andrew@xxxxxxxxxxxxxxx>
- Date: Sat, 3 Nov 2007 02:35:56 -0600
The others brought up some good points about you needing to read a book that covers .Net. These are fundamental issues and if you don't have a good understanding of them you're going to be running in to constant problems. However, I'm going to answer your root question so you'll recognize the tie back to your code while you're doing your reading.
System.IDisposable is an interface. An interface is basically a contract that your class makes to everything that uses your class. It defines a set of functionality that your class guarantees it supports. In this case the IDisposable interface tells everything else that it has a method called Dispose() that they can call. This Dispose method is typically used to clean up resources, however, it doesn't actually have to do anything.
You do this by adding it to your class
class StockManager : IDisposable
{
...Your Code...
public override void Dispose()
{
....Your Dispose Code....
}
}
Let me stress. Don't just use this and move on. Go get a book, read it and make sure you understand class inheritance, interfaces, garbage collection, etc.
--
Andrew Faust
andrew[at]andrewfaust.com
http://www.andrewfaust.com
"Sylvie" <sss@xxxxxx> wrote in message news:Ossc%23MTHIHA.3600@xxxxxxxxxxxxxxxxxxxxxxx
Hello,
I have a class, when I use this class like this, using (StockManager StMan = new StockManager()) { .......... }
it returns "error type used in a using statement must be implicitly convertible to 'System.IDisposable' "
How can I implement Dispose parts ?
My Class is;
class StockManager
{
public StockDataInterface StockData = null;
public StockManager()
{
StockData = new StockDataInterface();
}
public int CreateStock() { ..... }
}
.
- References:
- Implementing IDisposible for my Class
- From: Sylvie
- Implementing IDisposible for my Class
- Prev by Date: Re: about developing c# application
- Next by Date: Re: Parent Assembly from Component
- Previous by thread: Re: Implementing IDisposible for my Class
- Next by thread: Generic array is not recognized as correct parameter type
- Index(es):
Relevant Pages
|