-Value parameter: it does not contain any modifier. The parameters in the method are copies of real parameters. Changes in the parameters do not affect the values of real parameters in the memory. Real parameters are safe.
-Reference parameter: declared with a ref modifier. The passed parameter is actually a pointer to the real parameter. Therefore, operations in the method are directly performed on the real parameter, rather than copying a value. You can use this method to transmit parameters in both directions during method calling; to use parameters in Ref mode, the ref keyword must be explicitly specified in the method declaration and method call, and the real variable must be initialized before being passed to the method.
-Output parameter: declare with the out modifier. Similar to ref, it directly operates on real parameters. The out keyword must be explicitly specified during method declaration and method call. The out parameter declaration method does not require variables to be initialized before being passed to the method, because it only serves as the output. However, the out parameter must be assigned a value before the method is returned.
-Array parameters: declared with Params modifier. The Params keyword is used to declare the variable length parameter list. The method declaration can only contain one Params parameter.
Using system;
Class Test
{
Static void F (Params int [] ARGs)
{
Console. writeline ("array contains {0} elements:", argS. Length );
Foreach (int I in ARGs)
Console. Write ("{0}", I );
Console. writeline ();
}
Public static void main ()
{
Int [] A = {1, 2, 3 };
F ();
F (10, 20, 30, 40 );
F ();
}
}