+ 1
Passing variable to a method
How to receive a variable from a method and send a variable to another method. https://code.sololearn.com/cT5QY5ZmX6RT/?ref=app
9 ответов
+ 1
Akang Toshi,
If you want to pass <c>, <d> and <e> from receive( ) to getCdE( )? then change getCdE( ) to accept three parameters, and then call getCdE( ) from receive( ), passing <c>, <d>, and <e> as arguments.
What you need `ref` or `out` for again?
+ 2
// Hope this code helps you
static int c=0, d=0;
static float e=0;
static void Main(string[] args)
{
int a=3;
int b=4;
getCdE(a, b);
}
public static void getCdE(int valueA, int valueB)
{
c = valueA + valueB;
d = valueB - valueA;
e = valueB / 2;
float output = c + d + e;
Console.WriteLine(output);
}
+ 2
SoloProg Thanks for the answer but, i dont want that. The thing is I want something like one method that can accept paramater as well as that method can send out a variable like i have explained in my code. My code seems un-logical but, i need to do something like that. Perhaps I can acheive this by using call by reference or out something like that?
+ 1
Okay yes I see now. Thank you so much Ipang so simple yet, my My dumb brain won't figure it out. 😄😄
+ 1
Okay this may seem funny but I am still a newbie a self taught learner and I came across 'ref' and 'out' lastnight and lol i thought 'out' was for something like passing output paramater from the same method. 😭😄😄😄😄😁
+ 1
Okay, well the similarities of `ref` and `out` is, they both allows the changes of argument data in the called function to also reflect in the calling function.
The main difference is, arguments passed by `ref` specifier needs to be initialized in the calling function before they are passed through, but arguments passed by `out` doesn't need to be initialized in the calling function.
Hope I put it right though, but you may find it better explained here ...
https://www.dotnettricks.com/learn/csharp/difference-between-ref-and-out-parameters
0
No problem.
Just wondering what you plan to use `ref` or `out` for still ...
0
I have a very vague idea about it.
0
Or is it really something like that?