After the launch of Microsoft. NETArticleAlso appeared one after another. As an important language for Microsoft to compete with Java, C # has many advantages. This article will select some important knowledge in C # For detailed introduction,
Chapter 1: Parameters
1. 1 In Parameter
C:
Common Parameters
In Parameters
Out Parameter
Parameter Series
This chapter describes the last three methods.
In C language, you can pass the address parameter (real parameter) or the VaR indicator in Delphi to sort data. In C # language, how is it done? The "in" keyword can help you. This keyword can be used to pass the value you want to return through parameters.
Namespace testrefp
{
Using system;
Public class myclass
{
Public static void reftest (ref int ival1)
{
Ival1 + = 2;
}
Public static void main ()
{
Int I = 3; // The variable needs to be initialized.
Reftest (Ref I );
Console. writeline (I );
}
}
}
Note that the variable must be initialized first.
Result:
5
1. 2 out parameters
Do you want to return multiple values at a time? In C ++, this task is basically impossible. The "out" keyword in C # helps you easily complete the process. This keyword can return multiple values at a time through the parameter.
Public class mathclass
{
Public static int testout (Out int ival1, out int ival2)
{
Ival1 = 10;
Ival2 = 20;
Return 0;
}
Public static void main ()
{
Int I, j; // The variable does not need to be initialized.
Console. writeline (testout (Out I, out J ));
Console. writeline (I );
Console. writeline (j );
}
}
Result:
0 10 20
1. 3 parameter Series
The parameter series allows multiple related parameters to be represented by a single series. In other words, the parameter series 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 <args. length; I ++)
Console. writeline ("\ targs [{0}] = {1}", I, argS [I]);
}
Static void main (){
F ();
F (1 );
F (1, 2 );
F (1, 2, 3 );
F (New int [] {1, 2, 3, 4 });
}
}
The output result is as follows:
# Parameter: 0
# Parameter: 1
ARGs [0] = 1
# Parameter: 2
ARGs [0] = 1
ARGs [1] = 2
# Parameter: 3
ARGs [0] = 1
ARGs [1] = 2
ARGs [2] = 3
# Parameter: 4
ARGs [0] = 1
ARGs [1] = 2
ARGs [2] = 3
ARGs [3]