what's the equivalent

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • rodchar

    #1

    what's the equivalent

    hey all,
    vb has a static keyword for variables, what is charp's equivalent,plea se?

    static tempVar as String

    thanks,
    rodchar
  • Arne Vajhøj

    #2
    Re: what's the equivalent

    rodchar wrote:
    hey all,
    vb has a static keyword for variables, what is charp's equivalent,plea se?
    >
    static tempVar as String
    also static in C#

    as in:

    static string tempVar;

    Arne

    Comment

    • Ciaran O''Donnell

      #3
      RE: what's the equivalent

      static is a C# keyword,
      Its Shared in VB

      Ciaran O'Donnell

      "rodchar" wrote:
      hey all,
      vb has a static keyword for variables, what is charp's equivalent,plea se?
      >
      static tempVar as String
      >
      thanks,
      rodchar

      Comment

      • Peter Bromberg [C# MVP]

        #4
        RE: what's the equivalent

        The classic VB "static" keyword and the C# static (and VB.NET "Shared")
        modifiers are not the same thing. In classic VB, "static" was used to retain
        the value of a variable inside a function.

        Shared and Static in VB.NET and C# respectively mean, when applied to a
        variable, that all instances of the object share the same piece of data.

        Peter
        --
        Co-founder, Eggheadcafe.com developer portal:

        UnBlog:





        "rodchar" wrote:
        hey all,
        vb has a static keyword for variables, what is charp's equivalent,plea se?
        >
        static tempVar as String
        >
        thanks,
        rodchar

        Comment

        • Arne Vajhøj

          #5
          Re: what's the equivalent

          Peter Bromberg [C# MVP] wrote:
          The classic VB "static" keyword and the C# static (and VB.NET "Shared")
          modifiers are not the same thing. In classic VB, "static" was used to retain
          the value of a variable inside a function.
          Like C ?

          What about simply moving it outside the function (and make
          it static if it is a static method) ?

          Arne

          Comment

          • Peter Bromberg [C# MVP]

            #6
            Re: what's the equivalent

            You could certainly do that. But my point to the OP was, if you are comparing
            against classic VB there is no direct equivalent:

            http://msdn2.microsoft.com/en-us/library/z2cty7t8.aspx

            Peter

            --
            Co-founder, Eggheadcafe.com developer portal:

            UnBlog:





            "Arne Vajhøj" wrote:
            Peter Bromberg [C# MVP] wrote:
            The classic VB "static" keyword and the C# static (and VB.NET "Shared")
            modifiers are not the same thing. In classic VB, "static" was used to retain
            the value of a variable inside a function.
            >
            Like C ?
            >
            What about simply moving it outside the function (and make
            it static if it is a static method) ?
            >
            Arne
            >

            Comment

            • rodchar

              #7
              Re: what's the equivalent

              thanks everyone for the great feedback.

              "Peter Bromberg [C# MVP]" wrote:
              You could certainly do that. But my point to the OP was, if you are comparing
              against classic VB there is no direct equivalent:
              >
              http://msdn2.microsoft.com/en-us/library/z2cty7t8.aspx
              >
              Peter
              >
              --
              Co-founder, Eggheadcafe.com developer portal:

              UnBlog:

              >
              >
              >
              >
              "Arne Vajhøj" wrote:
              >
              Peter Bromberg [C# MVP] wrote:
              The classic VB "static" keyword and the C# static (and VB.NET "Shared")
              modifiers are not the same thing. In classic VB, "static" was used to retain
              the value of a variable inside a function.
              Like C ?

              What about simply moving it outside the function (and make
              it static if it is a static method) ?

              Arne

              Comment

              • David Anton

                #8
                RE: what's the equivalent

                The "static" local variable in VB is not limited to "classic" VB, but is
                alive and well in VB.NET also.
                There is no C# equivalent. It can be replaced by a class-level instance or
                static variable in C# (depending on whether the original method was an
                instance or static method), but this doesn't quite capture the usefulness of
                the local static variable.
                --
                David Anton
                Source code converters: Convert between C#, C++, Java, and VB with the most accurate and reliable source code converters

                Instant C#: VB to C# converter
                Instant VB: C# to VB converter
                Instant C++: C#/VB to C++ converter
                Instant Python: VB to Python converter


                "Peter Bromberg [C# MVP]" wrote:
                The classic VB "static" keyword and the C# static (and VB.NET "Shared")
                modifiers are not the same thing. In classic VB, "static" was used to retain
                the value of a variable inside a function.
                >
                Shared and Static in VB.NET and C# respectively mean, when applied to a
                variable, that all instances of the object share the same piece of data.
                >
                Peter
                --
                Co-founder, Eggheadcafe.com developer portal:

                UnBlog:

                >
                >
                >
                >
                "rodchar" wrote:
                >
                hey all,
                vb has a static keyword for variables, what is charp's equivalent,plea se?

                static tempVar as String

                thanks,
                rodchar

                Comment

                • Jon Skeet [C# MVP]

                  #9
                  RE: what's the equivalent

                  David Anton <DavidAnton@dis cussions.micros oft.comwrote:
                  The "static" local variable in VB is not limited to "classic" VB, but is
                  alive and well in VB.NET also.
                  There is no C# equivalent. It can be replaced by a class-level instance or
                  static variable in C# (depending on whether the original method was an
                  instance or static method), but this doesn't quite capture the usefulness of
                  the local static variable.
                  It does, however, *exactly* capture the semantics - as that's what the
                  VB.NET compiler converts the code into.

                  Personally I'm glad that C# doesn't have statics. Persistent state
                  should be a property of types and objects, not methods. Whenever a
                  method feels like it needs state, consider whether that state is
                  inherently part of the object, or whether it should be part of a new
                  class in its own right, which the object has a reference to an instance
                  of.

                  --
                  Jon Skeet - <skeet@pobox.co m>
                  http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
                  If replying to the group, please do not mail me too

                  Comment

                  • Ben Voigt

                    #10
                    Re: what's the equivalent


                    "Arne Vajhøj" <arne@vajhoej.d kwrote in message
                    news:45535d9b$0 $49199$14726298 @news.sunsite.d k...
                    Peter Bromberg [C# MVP] wrote:
                    >The classic VB "static" keyword and the C# static (and VB.NET "Shared")
                    >modifiers are not the same thing. In classic VB, "static" was used to
                    >retain the value of a variable inside a function.
                    >
                    Like C ?
                    >
                    What about simply moving it outside the function (and make
                    it static if it is a static method) ?
                    No if. C/C++ local statics are reused between all invocations, independent
                    of arguments (the this pointer is really an argument). So you can use a
                    global variable or a class static to get the same result.
                    >
                    Arne

                    Comment

                    • Ben Voigt

                      #11
                      Re: what's the equivalent


                      "Jon Skeet [C# MVP]" <skeet@pobox.co mwrote in message
                      news:MPG.1fbe37 1c66e9e77d98d5f 0@msnews.micros oft.com...
                      David Anton <DavidAnton@dis cussions.micros oft.comwrote:
                      >The "static" local variable in VB is not limited to "classic" VB, but is
                      >alive and well in VB.NET also.
                      >There is no C# equivalent. It can be replaced by a class-level instance
                      >or
                      >static variable in C# (depending on whether the original method was an
                      >instance or static method), but this doesn't quite capture the usefulness
                      >of
                      >the local static variable.
                      >
                      It does, however, *exactly* capture the semantics - as that's what the
                      VB.NET compiler converts the code into.
                      >
                      Personally I'm glad that C# doesn't have statics. Persistent state
                      should be a property of types and objects, not methods. Whenever a
                      method feels like it needs state, consider whether that state is
                      inherently part of the object, or whether it should be part of a new
                      class in its own right, which the object has a reference to an instance
                      of.
                      Agreed. While in C/C++ local statics have a use, namely caching the result
                      of a complex calculation/database lookup/object instantiation/etc., the VB
                      semantics are different, introducing *instance* variables. That's just
                      wrong.

                      Really, static should never be used to change the meaning of the program,
                      only to cache the result of an initialization which would take the same
                      value every time anyway.
                      >
                      --
                      Jon Skeet - <skeet@pobox.co m>
                      http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
                      If replying to the group, please do not mail me too

                      Comment

                      • David Anton

                        #12
                        RE: what's the equivalent

                        The class level variables simulate the functionality (our converters do
                        that), but I wouldn't say they capture the semantics well, since the
                        semantics of "local static" mean that the variable is off limits to other
                        methods.
                        I think your additional object idea does capture the semantics very well
                        (i.e., a method needing state is refactored to a new class where the local
                        static becomes an object property). We would incorporate that in our
                        converters, but it's a little too convoluted (it's easier for people to
                        accept the class variable conversion than a refactoring of their classes).
                        --
                        David Anton
                        Source code converters: Convert between C#, C++, Java, and VB with the most accurate and reliable source code converters

                        Instant C#: VB to C# converter
                        Instant VB: C# to VB converter
                        Instant C++: C#/VB to C++ converter
                        Instant Python: VB to Python converter


                        "Jon Skeet [C# MVP]" wrote:
                        David Anton <DavidAnton@dis cussions.micros oft.comwrote:
                        The "static" local variable in VB is not limited to "classic" VB, but is
                        alive and well in VB.NET also.
                        There is no C# equivalent. It can be replaced by a class-level instance or
                        static variable in C# (depending on whether the original method was an
                        instance or static method), but this doesn't quite capture the usefulness of
                        the local static variable.
                        >
                        It does, however, *exactly* capture the semantics - as that's what the
                        VB.NET compiler converts the code into.
                        >
                        Personally I'm glad that C# doesn't have statics. Persistent state
                        should be a property of types and objects, not methods. Whenever a
                        method feels like it needs state, consider whether that state is
                        inherently part of the object, or whether it should be part of a new
                        class in its own right, which the object has a reference to an instance
                        of.
                        >
                        --
                        Jon Skeet - <skeet@pobox.co m>
                        http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
                        If replying to the group, please do not mail me too
                        >

                        Comment

                        • Cor Ligthert [MVP]

                          #13
                          Re: what's the equivalent

                          David,

                          Exact, I find it always amazing how some C# users are always bloating that
                          it is something wrong.

                          I have seen that it can be a very useful feature.

                          Moreover I have as well seen that the average VB.Net programmers is more
                          trying to avoid Global variables than C# ones, with the result that the GC
                          can do its job better with those VB.Net developers. (In this case from the
                          static keyword it is opposite, that is why I am always very careful when I
                          use or advice the static keyword in VB.Net, however it fulfils the behaviour
                          of the average VB.Net developer to declare variables as late as possible).

                          Just something I mentioned, and is proven in this thread were is by more
                          people told to set things global. I would like that C# had better (and
                          easier) possibilities as in VB.Net to declare things in a method.

                          Cor


                          "David Anton" <DavidAnton@dis cussions.micros oft.comschreef in bericht
                          news:561B43AE-CB47-4E47-B09A-4D7B4827BEF5@mi crosoft.com...
                          The "static" local variable in VB is not limited to "classic" VB, but is
                          alive and well in VB.NET also.
                          There is no C# equivalent. It can be replaced by a class-level instance
                          or
                          static variable in C# (depending on whether the original method was an
                          instance or static method), but this doesn't quite capture the usefulness
                          of
                          the local static variable.
                          --
                          David Anton
                          Source code converters: Convert between C#, C++, Java, and VB with the most accurate and reliable source code converters

                          Instant C#: VB to C# converter
                          Instant VB: C# to VB converter
                          Instant C++: C#/VB to C++ converter
                          Instant Python: VB to Python converter
                          >
                          >
                          "Peter Bromberg [C# MVP]" wrote:
                          >
                          >The classic VB "static" keyword and the C# static (and VB.NET "Shared")
                          >modifiers are not the same thing. In classic VB, "static" was used to
                          >retain
                          >the value of a variable inside a function.
                          >>
                          >Shared and Static in VB.NET and C# respectively mean, when applied to a
                          >variable, that all instances of the object share the same piece of data.
                          >>
                          >Peter
                          >--
                          >Co-founder, Eggheadcafe.com developer portal:
                          >http://www.eggheadcafe.com
                          >UnBlog:
                          >http://petesbloggerama.blogspot.com
                          >>
                          >>
                          >>
                          >>
                          >"rodchar" wrote:
                          >>
                          hey all,
                          vb has a static keyword for variables, what is charp's
                          equivalent,plea se?
                          >
                          static tempVar as String
                          >
                          thanks,
                          rodchar

                          Comment

                          Working...