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. Two methods one output version 2.0

Two methods one output version 2.0

Scheduled Pinned Locked Moved C#
questioncsharpcssannouncement
6 Posts 4 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.
  • J Offline
    J Offline
    JMOdom
    wrote on last edited by
    #1

    I'm trying to learn C# coding and I've gotten to a point where I have a question. More or less. :rolleyes: If you have two methods like below public static void MethodOne() { result a; } public static void MethodTwo() { result b; } Can you use "result a" in methodTwo? :confused: I am assuming that "result a" is saved in its variable. If so what is the calling method? Thanks for any input, its appreciated. P.S. - Sorry about the other message with the same name. I think that I hit the wrong button. ;)

    C M 2 Replies Last reply
    0
    • J JMOdom

      I'm trying to learn C# coding and I've gotten to a point where I have a question. More or less. :rolleyes: If you have two methods like below public static void MethodOne() { result a; } public static void MethodTwo() { result b; } Can you use "result a" in methodTwo? :confused: I am assuming that "result a" is saved in its variable. If so what is the calling method? Thanks for any input, its appreciated. P.S. - Sorry about the other message with the same name. I think that I hit the wrong button. ;)

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      JMOdom wrote:

      Can you use "result a" in methodTwo?

      What do you mean by result a ? If it's a variable, no. It needs to be a member.

      Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )

      J 1 Reply Last reply
      0
      • C Christian Graus

        JMOdom wrote:

        Can you use "result a" in methodTwo?

        What do you mean by result a ? If it's a variable, no. It needs to be a member.

        Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )

        J Offline
        J Offline
        JMOdom
        wrote on last edited by
        #3

        OK, exchange "results a" and "results b" for "return a" and "return b".:(

        C V 2 Replies Last reply
        0
        • J JMOdom

          I'm trying to learn C# coding and I've gotten to a point where I have a question. More or less. :rolleyes: If you have two methods like below public static void MethodOne() { result a; } public static void MethodTwo() { result b; } Can you use "result a" in methodTwo? :confused: I am assuming that "result a" is saved in its variable. If so what is the calling method? Thanks for any input, its appreciated. P.S. - Sorry about the other message with the same name. I think that I hit the wrong button. ;)

          M Offline
          M Offline
          Mike Hankey
          wrote on last edited by
          #4

          Its a matter of scope If you have the following; static int resulta = 0; public static void MethodOne() { result a; } public static void MethodTwo() { result b; result a; //Is legal } then result a can be referenced in MethodTwo but if you have public static void MethodOne() { int result a; } public static void MethodTwo() { result b; result a; //Is not valid because it is not in scope } Hope this helps and that I understood you correctly Mike

          Everybody gotta be somebody

          1 Reply Last reply
          0
          • J JMOdom

            OK, exchange "results a" and "results b" for "return a" and "return b".:(

            C Offline
            C Offline
            Christian Graus
            wrote on last edited by
            #5

            If you return it, then you'd need to pass it as a parameter. Otherwise, it's out of scope, unless it's a member.

            Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )

            1 Reply Last reply
            0
            • J JMOdom

              OK, exchange "results a" and "results b" for "return a" and "return b".:(

              V Offline
              V Offline
              Vikram A Punathambekar
              wrote on last edited by
              #6

              To add to what Christian told you, you will have to change the return type from void to whatever a and b are.

              Cheers, Vikram.


              The cold will freeze our stares We won't care...

              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