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. IDisposable

IDisposable

Scheduled Pinned Locked Moved C#
question
3 Posts 3 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.
  • S Offline
    S Offline
    S O S
    wrote on last edited by
    #1

    I am wondering, what is the point of implementing IDisposable? Why not just do whatever is needed in the destructor?

    C A 2 Replies Last reply
    0
    • S S O S

      I am wondering, what is the point of implementing IDisposable? Why not just do whatever is needed in the destructor?

      C Offline
      C Offline
      Chris Austin
      wrote on last edited by
      #2

      C# dosen't have a delete operator so, we don't have destructors in the C++ sense. You have to override the finalize method which looks strangely like a C++ destructor :) But, in order to exercise a more percise destructor like control .net wants us to implement the Dispose pattern which can be easily done through IDisposable. Another bennifit is that much of .net uses this pattern; also a client app using your class class will be able test for this interface using the "as" or "is" operators..making it a tad more reuasable. Hey don't worry, I can handle it. I took something. I can see things no one else can see. Why are you dressed like that? - Jack Burton

      1 Reply Last reply
      0
      • S S O S

        I am wondering, what is the point of implementing IDisposable? Why not just do whatever is needed in the destructor?

        A Offline
        A Offline
        Andres Manggini
        wrote on last edited by
        #3

        Here's the answer: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconimplementingdisposemethod.asp[^] http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpgenref/html/cpconfinalizedispose.asp[^] Remember, .NET doesn't have deterministic finalization. Hope this helps. Andres Manggini. Buenos Aires - Argentina.

        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