Resources » Code Snippets » C# Syntax

Param Arrays in C#


Posted Date: 15-Sep-2009  Last Updated:   Category: C# Syntax    
Author: Member Level: Gold    Points: 5



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.


Did you like this resource? Share it with your friends and show your love!

Responses to "Param Arrays in C#"

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

Feedbacks      

Post 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:   Sign In to fill automatically.
    Email: (Will not be published, but required to validate comment)



    Type the numbers and letters shown on the left.


    Submit Article     Return to Article Index

    Subscribe to Subscribers
    Active Members
    TodayLast 7 Daysmore...

    Awards & Gifts
    Talk to Webmaster Tony John

    Online Members

    Priya jain
    More...
    Copyright © SpiderWorks Technologies Pvt Ltd., Kochi, India