Sunday, July 4, 2010

variable arguments

2 methods are defined as below:

public void Add(int a, int b)
{
Console.WriteLine("2 parameter function");
Console.WriteLine(a + b);
}

public void Add(params int[] val)
{
int sum=0;
Console.WriteLine("variable argument method");

for (int i = 0; i < val.Length; i++)
{
sum += val[i];
}
Console.WriteLine(sum);

}

Which method will be called on following statements :

1. Add ();
2. Add ( 4,6);
3. Add (10, 20, 30);

No comments:

Post a Comment