Welcome To Shadab's Blog

Programming Blog to learn C# , java, Sql Server 2005 and many more things.





About Me

My photo
Bokaro, Jharkhand, India

Saturday, December 19, 2009

How to pass Arrary as Parameter

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

No comments:

Post a Comment