The parameter passing is nothing but passing a value or reference to method.
The parameter passing can be two types in c#. They are
- Value type parameter passing
- Reference type parameter passing
Value type parameter passing:
In value type parameter passing we passing the value to method like,
class Program
{
static void Main(string[] args)
{
Program p = new Program();
p.method(2, 3);//pass by value
}
void method(int i, int j)
{
Console.WriteLine("pass by value : "+(i + j).ToString());
}
}
Reference type parameter passing:
In reference parameter passing passing the varible or object reference to method.
class Program
{
static void Main(string[] args)
{
int i = 5, j = 5;
method1(ref i, ref j); //pass by ref
}
static void method1(ref int i, ref int j)
{
Console.WriteLine("pass by reference : " + ((i+1) + (j+1)).ToString());
Join the conversation! Your thoughts help the community grow.