Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. couple of questions

couple of questions

Scheduled Pinned Locked Moved C#
question
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    kalyan_2416
    wrote on last edited by
    #1

    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)

    S 1 Reply Last reply
    0
    • K kalyan_2416

      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)

      S Offline
      S Offline
      Scott Dorman
      wrote on last edited by
      #2

      Since you are asking this in the C# forum, I'm going to assume you want to know specifically about C#.

      kalyan_2416 wrote:

      1. 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:

      1. 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]

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups