C # concise tutorial (3)

zhaozj2021-02-17  77

C # concise tutorial (3)

Disclaimer: I am in translation, add some of my own opinions and some other comparisons, I hope you can make everyone understand more, understand more.

If you have any suggestions, please mail: efoxxx@263.net

By the way, the brother of "finding the C # compiler" in the expert clinic, how can I have not received the C # compiler you promised, urgent, and send me a busy busy, Thanks!

OUT and REF parameters in C #

The OUT and REF parameters are used to bring back the return value in the parameters pass to the method.

These two parameters are useful in the case where you need to return more than one return value.

◆ OUT parameters

The OUT parameter can be used to let the same variable parameter from both the return value. (A point like C in C)

Public class mathclass {public static int testout (out INT IVAL1, OUT IVAL2) {ival1 = 10; ival2 = 20; Return 0;}

Public static void main () {INT I, J; // Variable I, J does not need to initialize Console.Writeline (Testout (Out I, Out J)); Console.Writeline (i); console.writeLine (j);} }

Efoxxx Supplement:

Here I want to add a classic C procedure for Tan Haoqiang teacher: SWAP

Public class swapclass {public static int swapout (out Ivest Ival1, out IVAL2) {int Temp;

Temp = IVAL1; IVAL1 = IVAL2; IVAL2 = TEMP;

Return 0;}

Public static void main () {INT I, J; // Variable I, J does not need to initialize swapout (Out I, Out J); console.writeline (i); console.writeline (j);}}

◆ REF parameter (reference)

The same is the same as Java and C .

You can also get more than one return parameter with REF.

Namespace TestRefp

{

Using system;

Public Class Myclass

{

Public Static Void Reftest (Ref Int Ival1)

{

Ival1 = 2;

}

Public static void main ()

{

Int i; // variable need not be initialized

i = 3;

Reftest (Ref i);

Console.writeLine (i);

}

}

}

转载请注明原文地址:https://www.9cbs.com/read-31376.html

New Post(0)