8.26.2012

Difference between Method Parameters and Method Arguments

Difference between Method Parameters and Method Arguments
S.No Method Parameters Method Arguments
1
Method parameters get their actual values from the arguments that are specified when the method is invoked.
i.e.,"parameters" refer to names
Method arguments are itself having a value.
i.e.,"arguments" refer to values bound to those names.



Example:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Sample
{
class Program
{
public static void Main()
{
int N1 = 10;
int N2 = 20;
//N1 and N2 are method arguments
int Total = Sum(N1, N2);
Console.WriteLine(Total);
}

//FNum and SNum are method parameters

public static int Sum(int FNum, int SNum)
{
int Sum = FNum + SNum;
return Sum;
}
}
}

Note: The arguments must be compatible with the parameter type but the argument name used in the calling code does not have to be the same as the parameter named defined in the method which is clear in the above example

Where,
FNum and SNum are method parameters, and
N1 and N2 are method arguments.

No comments:

Post a Comment