CSharp output parameter learning
1. A function may produce multiple valuable calculations, but only one data can be returned using the evaluate statement.
If multiple pieces of useful data are returned
The main results are as follows: (1) citing the parameter ref can change the value of the parameter, so the calculation result can be fed back to the tone function naturally.
(2) use the output parameter out to return useful calculation results.
The difference between ref and out:
A ref parameter must be assigned before it is passed into the function
The parameter of type out does not need to be assigned before it is passed into the function, and even if it is assigned, it will be ignored.
So the out parameter can only be used to return the result from the function, not to pass data to the function. You must assign a value to the out parameter before the end of the function.
Put on the code, just talk but not practice fake tricks.
Using System
Using System.Collections.Generic
Using System.Linq
Using System.Text
Using System.Threading.Tasks
Namespace reference
{
Class Program
{
Static void Main (string [] args)
{
/ *
Double a = Convert.ToDouble (Console.ReadLine ())
Double b = Convert.ToDouble (Console.ReadLine ())
Double result = Bigger (afort b)
Console.WriteLine ("maximum: {0}", result)
Console.ReadKey ()
, /
Double r = 156
Double circumference
Double area = CalculateCircle (r, out circumference)
Console.WriteLine ("perimeter:" + circumference)
Console.WriteLine ("area:" + area)
Console.ReadKey ()
}
/ * here are the formal parameters * /
Static double Bigger (double x, double y) {
Double temp = (x > = y)? X: y
Return temp
/ *
If (x > y)
{
Return x
}
Else {
Return y
}
, /
}
Static double CalculateCircle (double r, out double c) {
C = 2 * Math.PI * r
Double s = Math.PI * r * r
Return s
}
}
}