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

variables

Scheduled Pinned Locked Moved C#
csharpquestion
9 Posts 6 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.
  • T Offline
    T Offline
    toto_2010
    wrote on last edited by
    #1

    when is that local variables are created and destroyed ,C#? thanks.

    P P 2 Replies Last reply
    0
    • T toto_2010

      when is that local variables are created and destroyed ,C#? thanks.

      P Offline
      P Offline
      Pete OHanlon
      wrote on last edited by
      #2

      You really need to buy this book[^] and read it. The point of the forums is not to teach people the basics of the language - the forums are here to help people with specific problems they may have.

      "WPF has many lovers. It's a veritable porn star!" - Josh Smith

      As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.

      My blog | My articles | MoXAML PowerToys | Onyx

      1 Reply Last reply
      0
      • T toto_2010

        when is that local variables are created and destroyed ,C#? thanks.

        P Offline
        P Offline
        PIEBALDconsult
        wrote on last edited by
        #3

        What difference does it make?

        L 1 Reply Last reply
        0
        • P PIEBALDconsult

          What difference does it make?

          L Offline
          L Offline
          Luc Pattyn
          wrote on last edited by
          #4

          it may be important when a method needs huge amounts of local variables: it may work well when they get allocated and freed by the smallest code block that contains them, it may throw a StackOverflowException when all of them get allocated upfront. :)

          Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]


          Prolific encyclopedia fixture proof-reader browser patron addict?
          We all depend on the beast below.


          P 1 Reply Last reply
          0
          • L Luc Pattyn

            it may be important when a method needs huge amounts of local variables: it may work well when they get allocated and freed by the smallest code block that contains them, it may throw a StackOverflowException when all of them get allocated upfront. :)

            Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]


            Prolific encyclopedia fixture proof-reader browser patron addict?
            We all depend on the beast below.


            P Offline
            P Offline
            PIEBALDconsult
            wrote on last edited by
            #5

            Luc Pattyn wrote:

            when a method needs huge amounts of local variables

            :| Refactor?

            OriginalGriffO 1 Reply Last reply
            0
            • P PIEBALDconsult

              Luc Pattyn wrote:

              when a method needs huge amounts of local variables

              :| Refactor?

              OriginalGriffO Offline
              OriginalGriffO Offline
              OriginalGriff
              wrote on last edited by
              #6

              Isn't that going to use more stack space? Return addresses, and so forth...

              I have learnt that you can not make someone love you, all you can do is stalk them and hope they panic and give in. Apathy Error: Don't bother striking any key.

              "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
              "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

              L 1 Reply Last reply
              0
              • OriginalGriffO OriginalGriff

                Isn't that going to use more stack space? Return addresses, and so forth...

                I have learnt that you can not make someone love you, all you can do is stalk them and hope they panic and give in. Apathy Error: Don't bother striking any key.

                L Offline
                L Offline
                Luc Pattyn
                wrote on last edited by
                #7

                Yeah, well, you could delegate some data to local variables in a different method, executed by some other thread. So basically implement an in-stack database, using Invoke to call on a single GetSet() method. But then that may be over-engineering the situation a bit. :)

                Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]


                Prolific encyclopedia fixture proof-reader browser patron addict?
                We all depend on the beast below.


                L OriginalGriffO 2 Replies Last reply
                0
                • L Luc Pattyn

                  Yeah, well, you could delegate some data to local variables in a different method, executed by some other thread. So basically implement an in-stack database, using Invoke to call on a single GetSet() method. But then that may be over-engineering the situation a bit. :)

                  Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]


                  Prolific encyclopedia fixture proof-reader browser patron addict?
                  We all depend on the beast below.


                  L Offline
                  L Offline
                  Lost User
                  wrote on last edited by
                  #8

                  Would be a nice answer to stump his teacher and set a new bar for homework, though :)

                  I are Troll :suss:

                  1 Reply Last reply
                  0
                  • L Luc Pattyn

                    Yeah, well, you could delegate some data to local variables in a different method, executed by some other thread. So basically implement an in-stack database, using Invoke to call on a single GetSet() method. But then that may be over-engineering the situation a bit. :)

                    Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]


                    Prolific encyclopedia fixture proof-reader browser patron addict?
                    We all depend on the beast below.


                    OriginalGriffO Offline
                    OriginalGriffO Offline
                    OriginalGriff
                    wrote on last edited by
                    #9

                    Remind me to suggest it at the next code review... :-D

                    I have learnt that you can not make someone love you, all you can do is stalk them and hope they panic and give in. Apathy Error: Don't bother striking any key.

                    "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
                    "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

                    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