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