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. Should I write destructors for all the classes

Should I write destructors for all the classes

Scheduled Pinned Locked Moved C#
7 Posts 5 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
    Sivaprasad C
    wrote on last edited by
    #1

    Hi Should I write destructors for all the classes or do all classes have destructors by default(In built)

    Regards, Sivaprasad

    D S S 3 Replies Last reply
    0
    • S Sivaprasad C

      Hi Should I write destructors for all the classes or do all classes have destructors by default(In built)

      Regards, Sivaprasad

      D Offline
      D Offline
      dengboo
      wrote on last edited by
      #2

      No, I don't think so. .Net Framework has its own Garbage Collection.

      --------------------------------- Believe what you saw!

      1 Reply Last reply
      0
      • S Sivaprasad C

        Hi Should I write destructors for all the classes or do all classes have destructors by default(In built)

        Regards, Sivaprasad

        S Offline
        S Offline
        Sathesh Sakthivel
        wrote on last edited by
        #3

        No Need

        SSK. Anyone who says sunshine brings happiness has never danced in the rain.

        S 1 Reply Last reply
        0
        • S Sathesh Sakthivel

          No Need

          SSK. Anyone who says sunshine brings happiness has never danced in the rain.

          S Offline
          S Offline
          Sivaprasad C
          wrote on last edited by
          #4

          If .net frame work handles this...Y should I write destructors manually in some cases and

          Regards, Sivaprasad

          B 1 Reply Last reply
          0
          • S Sivaprasad C

            If .net frame work handles this...Y should I write destructors manually in some cases and

            Regards, Sivaprasad

            B Offline
            B Offline
            Bino B
            wrote on last edited by
            #5

            www.codepal.co.nr

            S 1 Reply Last reply
            0
            • S Sivaprasad C

              Hi Should I write destructors for all the classes or do all classes have destructors by default(In built)

              Regards, Sivaprasad

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

              .NET does not have the same concept of destructors as C++ does. The ~T syntax (for C#) you see (where T is the name of the class) is actually a finalizer. You should almost never need to write a finalizer. What you are probably thinking of is a Dispose method or the IDisposable interface. Really the only time you need to use this in your own class is when you are managing native resources (unmanaged memory) yourself or you are internally managing a class that implements it. There are a lot of references available, both here on CP and the web. You can check out this article[^] for more information.

              Scott.


              —In just two days, tomorrow will be yesterday. [Forum Guidelines] [Articles] [Blog]

              1 Reply Last reply
              0
              • B Bino B

                www.codepal.co.nr

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

                And how does this answer his question?

                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