Working With Params Keyword or Param Array Object In C#

We can use Params keyword in a method which can takes multiple number of arguments. But after this keyword in method declaration it won't accept any other arguments so all the arguments must be in before of this argument.

Using this params keyword in method declaration we can work two ways like an arraylist and hashtable.

In an arraylist we can pass array of values of same type, in the same manner if we want to pass an array of different datatypes of values also we can pass by declaring that method as Object type.
Both examples are given.

public class paramclass
public static void useinttypeparam(params int[] list)
for (int i=0;i {
Public static void usedifftypeparam(params object[] list)
for (int i=0;i < list.Length;i++)
Console.Write(list[i]+" ");
static void Main()
// We can send Comma seperated list of arguments
usedifftypeparam(1,'a',"param Keyword");
// we can also send directly an array as argument
int[] myarr={3,5,6,7,8}



Output :

1 2 3 4

1 a param Keyword
3 5 6 7 8

I thought it is better than hashtable also. Hope this is help full to You. Thanks

Sekhar Babu


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: