I am re-writing an old VB application in C#, this application is some sort of calculator. So it consists of a bunch of subroutines which takes some values, and calculate some new values(intermediate results), which is later used in some other calculations.
The way they do this is like this:
int in = 4;
Call routine(in, outFromRoutine1);
Call routine2(outFromRoutine1, outFromRoutine2);
The default in VB6 is pass by reference, so I could do the same in C# like this:
int in = 4;
int outFromRoutine2 = 0;
Routine(in, ref outFromRoutine1);
int outFromRoutine2 = 0;
Routine2(outFromRoutine1, ref outFromRoutine2);
But I am just thinking if this is considered a weird way to do this in C#? That this is just some sort of weird VB way of doing it. Is there any problem with doing it like this in C# also?
C# offers both the ref (parameter is input and output) and out (parameter is output only) that allow you to use parameters to the method as outputs from the method as well. That said, in general, it is considered to be best practice use return statements to return values in C#. If you are moving forward with visual studio 2017, you can also use the new function of C# that allows you to return multiple values from a single method.