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
Example of out parameter in C#
using System;
class out_demo
{
public void add(out int num)
{
num=90; //set the value in reference of num
}
public static void Main()
{
int num; //local variable but not initialized
out_demo obj=new out_demo();
obj.add(out num);
Console.WriteLine(num);
}
}
//output will be
//90
//now we can say that in case of out parameter value transfered out from the method named add()
class out_demo
{
public void add(out int num)
{
num=90; //set the value in reference of num
}
public static void Main()
{
int num; //local variable but not initialized
out_demo obj=new out_demo();
obj.add(out num);
Console.WriteLine(num);
}
}
//output will be
//90
//now we can say that in case of out parameter value transfered out from the method named add()
Subscribe to:
Posts (Atom)