couple of questions
-
hi all 1) i want to know more difference between destructor and dispose method. if u have any articles please let me know 2) Base b=new Derived() derived d=new Base() which one is illegal and why i have found second question in a paper i could not get a answer for (oops concepts)
-
hi all 1) i want to know more difference between destructor and dispose method. if u have any articles please let me know 2) Base b=new Derived() derived d=new Base() which one is illegal and why i have found second question in a paper i could not get a answer for (oops concepts)
Since you are asking this in the C# forum, I'm going to assume you want to know specifically about C#.
kalyan_2416 wrote:
- i want to know more difference between destructor and dispose method. if u have any articles please let me know
First, take a look at this article[^]. It will give you an explanation of the IDisposable interface and the Dispose method. C# does not have a destructor like C++ does. It does, however, have a finalizer which is defined using the same syntax as a C++ destructor, namely the ~T syntax (where T is the name of the class). The Dispose method is described by the IDisposable interface and is used primarily when an object mantains unmanaged memory. It provides a way for the caller to explicitly indicate that it is done using that object and that it is safe to cleanup managed or unmanaged resources. Internally, the Dispose method knows how to cleanup those unmanaged resources. This is important because the GC in .NET doesn't know any thing about what to do with these unmanaged resources. A finalizer is a "special" function that helps guarantee that the object will be properly cleaned up. That being said, there are very few times when you should implement a finalizer as there are a lot of specific rules that apply in order to get them right.
kalyan_2416 wrote:
- Base b=new Derived() derived d=new Base() which one is illegal and why
Which one do you think is illegal? Have you tried to create this code in Visual Studio? If you think about what you are trying to accomplish with this bit of code and understand what the names mean it should become very clear. If you think of derivation as a tree structure, the child classes derive from the base class, with each child class becoming increasingly more specialized the further away from the base class they are.
Scott.
—In just two days, tomorrow will be yesterday. [Forum Guidelines] [Articles] [Blog]