C # Key knowledge detailed (1)

zhaozj2021-02-11  178

cutting edge

After Microsoft's .NET is launched, the relevant article on C # has also appeared, as an important way to Microsoft, a language against Java, C # has many advantages. This article will select some important knowledge in C # languages,

Chapter 1: Parameters

1.1 in parameter

Four parameters of C # species: General parameter IN parameter OUT parameter number The number of this chapter will introduce the three uses.

In the C language you can pass the address (ie, inactive) or the Delphi language passes the data sorting by the VAR indicator to pass the address parameters, how do you do it in the C # language? "IN" keyword can help you. This keyword can pass the parameters to pass the value you want to return. Namespace testRefp {sale system; public class myclass {public static void reftest (Ref int IVAL1) {ival1 = 2;} public static void main () {INT i = 3; // Variable needs to initialize REFTEST (REF I); console .Writeline (i);}}}

It must be noted that variables must be initialized first.

result:

5

1.2 OUT parameters

Do you want to return multiple values ​​at a time? This task is basically impossible to complete the task in the C language. "OUT" keyword in C # can help you complete it. This keyword can return multiple values ​​at a time by parameter. 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 does not need to initialize. Console.writeline (Testout (Out I, Out J)); Console.WriteLine (i); console.writeLine (j);}}

result:

0 10 20

1.3 parameter number

The parameter number list enables multiple associated parameters to be represented by a single number, and the parameter number is the length of the variable.

Using system;

Class test {static void f (params int [] args {console.writeline ("# parameter: {0}", args.length); for (int i = 0; i

Static void main () {f (); f (1); f (1, 2); f (1, 2, 3); f (new int in 1, 2, 3, 4});}}

The following is the output result:

# Parameters: 0 # Parameters: 1Args [0] = 1 # Parameters: 2Args [0] = 1Args [1] = 2 # Parameters: 3ARGS [0] = 1Args [1] = 2Args [2] = 3 # Parameters: 4Args [0] = 1Args [1] = 2ARGS [2] = 3ARGS [3]

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

New Post(0)