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.
Sekhar Babu
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
Console.Write(List[i]+"");
}
Console.WriteLine();
}
Public static void usedifftypeparam(params object[] list)
{
for (int i=0;i < list.Length;i++)
{
Console.Write(list[i]+" ");
}
Console.WriteLine();
}
static void Main()
{
// We can send Comma seperated list of arguments
useinttypeparam(1,2,3,4);
usedifftypeparam(1,'a',"param Keyword");
// we can also send directly an array as argument
int[] myarr={3,5,6,7,8}
Useinttypeparam(myarr);
}
}
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
http://chandrasekharam.blogspot.in