views:

51

answers:

3

How can I pass the Parameter to a function. for example

 public void GridViewColumns(params ClassName[] pinputparamter)
 {
 }

and Class is as given below

public Class ClassName
{
     public string Name{get;set;}
     public int RecordID{get;set;}
}

can anyone has idea?

+4  A: 

params means that the method can accept any number of parameters of type ClassName. Example of calling it with two instances of ClassName:

GridViewColumns(new ClassName(), new ClassName());

or

ClassName a = new ClassName();
ClassName b = new ClassName();
ClassName c = new ClassName();
GridViewColumns(a, b, c);
Darin Dimitrov
+1  A: 

First thing first, you have to create an object of the class in your main().

ClassName myObject = new ClassName();

then you can pass it as a parameter in your function.

GridViewColumns(myObject);

Hope this helps..

manuel
A: 

Also you can pass instances of ClassName as Array:

ClassName[] arr = new ClassName[]{new ClassName(), new ClassName()};
GridViewColumns(arr);

More details here.

iburlakov