1.Parameter Value
Namespace _ 06. Method _ 2 _
{
Public partial class Form1: Form
{
Public Form1 ()
{
InitializeComponent ();
}
Private void Form1_Load (object sender, EventArgs e)
{
Int I = 0;
MessageBox. Show ("I =" + I );
}
Public void Method (int I) // public static void ValueMethod (int I)
{
I ++;
}
}
}
2.Reference parameters
Namespace _ 06. Method _ 2 _
{
Public partial class Form1: Form
{
Public Form1 ()
{
InitializeComponent ();
}
Private void Form1_Load (object sender, EventArgs e)
{
Int I = 0;
Method (I );
MessageBox. Show ("I =" + I );
Int j = 0;
ReferenceMethod (ref j );
MessageBox. Show ("j =" + j );
}
Public void Method (int I) // public static void ValueMethod (int I)
{
I ++;
}
Public static void ReferenceMethod (ref int I)
{
I ++;
}
}
}
3.Output Parameters
Namespace _ 06. Method _ 2 _
{
Public partial class Form1: Form
{
Public Form1 ()
{
InitializeComponent ();
}
Private void Form1_Load (object sender, EventArgs e)
{
Int I = 0;
Method (I );
MessageBox. Show ("I =" + I );
Int j = 0;
ReferenceMethod (ref j );
MessageBox. Show ("j =" + j );
Int k = 0;
OutputMethod (out k );
MessageBox. Show ("k =" + k );
}
Public void Method (int I) // public static void ValueMethod (int I)
{
I ++;
}
Public static void ReferenceMethod (ref int I)
{
// I = 0;
I ++;
}
Public static void OutputMethod (out int I)
{
I = 0;
I ++;
}
}
}
4.Passing variable parameters to methods
Namespace _ 06. Method _ 2 _
{
Public partial class Form1: Form
{
Public Form1 ()
{
InitializeComponent ();
}
Private void Form1_Load (object sender, EventArgs e)
{
MessageBox. Show (addi (1, 2, 3) + "");
}
Static int addi (params int [] values)
{
Int sum = 0;
Foreach (int I in values)
Sum + = I;
Return sum;
}
}
}
5.Using arrays as method parameters (reference type)
Namespace _ 06. Method _ 2 _
{
Public partial class Form1: Form
{
Public Form1 ()
{
InitializeComponent ();
}
Private void Form1_Load (object sender, EventArgs e)
{
Int [] arr ={ 100,200,300,400 };
PrintArr (arr );
Foreach (int I in arr)
MessageBox. Show (I + "");
}
Static void PrintArr (int [] arr)
{
For (int I = 0; I <arr. Length; I ++)
Arr [I] = I;
}
}
}