Param Arrays in C#

Hello Friends,

This article contains a sample example of param arrays with some definition...

While declaring a method if you are not sure about the number of arguments passed as a parameter, You can use the Param Array....

The following code is an example of using the Param Array in the methods parameter List:


Using System;
namespace ParamArrays
{
Public class ParamExample
{
Public int Adding_ArrayElement(params int[] List)
{
int Total=0;
foreach(int I in List)
{
Total +=I;
}
return Total;
}
}
class Tester
{
static void Main(string[] args)
{
ParamExample Param_Exam = new ParamExample();
int Total = Param_Exam.Adding_ArrayElement(1,2,3,4,5,6,7);
Console.WriteLine("The Result is {0}",Total);
Console.ReadLine();
}
}
}

Note: In the parameter list of a method ,Param array should be the last parameter.

This is the example which I have done when IAm learning C#.So, please don't misuse it.
If This is good.just message me....

Thanks & Regards,
Datta.G
Jr. Software Engg.


Comments

No responses found. Be the first to comment...


  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:
    Email: