[英]How To Pass Class As Params to Function
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? 谁能有主意?
params
means that the method can accept any number of parameters of type ClassName
. params
意味着该方法可以接受ClassName
类型的任意数量的参数。 Example of calling it with two instances of ClassName: 用两个ClassName实例调用它的示例:
GridViewColumns(new ClassName(), new ClassName());
or 要么
ClassName a = new ClassName();
ClassName b = new ClassName();
ClassName c = new ClassName();
GridViewColumns(a, b, c);
First thing first, you have to create an object of the class in your main(). 首先,您必须在main()中创建该类的对象。
ClassName myObject = new ClassName();
then you can pass it as a parameter in your function. 那么您可以在函数中将其作为参数传递。
GridViewColumns(myObject);
Hope this helps.. 希望这可以帮助..
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.