Question

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?

Was it helpful?

Solution

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);

OTHER TIPS

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..

Also you can pass instances of ClassName as Array:

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

More details here.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top