what's Param?

what's Param?

Params:-The params keyword is used to describe methods that can receive any number of parameters of the specified type, and it results in extra allocations and reduced performance but improves the flexibility of the calling patterns.

The main use of the params keyword is to give the ability to create functions that take a variable number of arguments.

Example:-

Public int sumnumber(params int[] list)
{
  int sum = 0;
  foreach (int i in list)
    sum += i;
  return sum;
}
Public static void Main()
{
int ans1 = sumnumber(1);

int ans2 =  sumnumber(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);

int ans3 =  sumnumber(new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 });

int ans4 =  sumnumber()


}

OUTPUT:-
1
55
55
0

By:kamal
Date:2012-10-10 00:00:00

Post Your Answers


User Email:

User Name:
Answers:

Related C Links

C interview questions and answers for experienced and fresher