Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

CSharp output parameter learning

2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

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

}

}

}

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report