If youre creating an utility in C#, youll be used to calling functions to return specific values.
Sometimes, there may be cases where you may need to return multiple values from a single function.
There are different ways that you’re able to achieve this.
One is to return several values inside a single array.
you’ve got the option to also assign values to multiple global variables, from inside the function.
What Is an Out Parameter?
The standard way to return a value from a function is to use the “return” keyword.
it’s possible for you to also explore otherbasic programming principles.
Another way to retrieve a value from a function is to use an “out” parameter instead.
you’re free to declare an out parameter within the signature of the method.
Instead of using the return keyword, you must always assign a value to the out parameter.
When you call the Calculation() method, pass in a variable for the out parameter.
In this case, the value “30” will output.
you’re able to explore more about how to create and use classes in C#.