you can pass array as parameter by using params keyword in C#.
Following program is shown how to pass array as parameter
using System;
class Array_parameter
{
public void display(int num,params int [] arr1)
{
Console.WriteLine("Num ="+num);
Console.WriteLine("Array's values are ");
foreach(int i in arr1)
{
Console.WriteLine(i);
}
}
public static void Main ()
{
Array_parameter obj=new Array_parameter();
obj.display(44,12,2,25,45,85);
}
}
/*here when display method is called then some argument is send
together first argument inserted into varible num in display method
and rest element are goes into reference of arr1
out will be--
Num=44
Array's values are
12
2
25
45
85
About Me
Saturday, December 19, 2009
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment