[英]Method that accept n Number of Parameters in C #
I am Developing an windows Application, oftentimes I need to clear the Textboxes whenever the user save the Record or click on clear button. 我正在开发一个Windows应用程序,通常我需要在用户保存记录或单击清除按钮时清除文本框。 Currently i am using this code txtboxname.text=string.empty;
目前我正在使用此代码txtboxname.text = string.empty; for each textbox
对于每个文本框
So can it be possible to write a method that accept the n number of parameter like reading the all the Textboxes in an array and using foreach we can clear them 那么可以编写一个接受n个参数的方法,比如读取数组中的所有Textbox并使用foreach我们可以清除它们
the main requirement is to write a method which accept the n number of parameter ie The parameter size will be unknown. 主要要求是编写一个接受n个参数的方法,即参数大小是未知的。
If any body having idea about how to do this then please help me. 如果有任何机构知道如何做到这一点,请帮助我。 Thanks in Advance.
提前致谢。
您可以使用params
,例如Foo(params Bar[] bars)
将接受任意数量的Bar
实例作为输入。
You could also pass a collection eg a dictionary or List to your method as a parameter. 您还可以将集合(例如字典或列表)作为参数传递给方法。
Eg 例如
public void DoSomething(List<myCustomObject> lst){
...
}
是的,您可以将一个TextBoxes TextBox[]
数组作为方法的paremter,然后您可以在方法中迭代它们。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.