我可以在C#中运行多个控件但是相同的方法

Pol*_*ich 7 c#

例如

txtUnitTotalQty.Text = "";   
txtPrice.Text = "";
txtUnitPrice.Text = "";
lblTotalvalue.Text = "";
Run Code Online (Sandbox Code Playgroud)

喜欢的东西

(txtUnitTotalQty, txtPrice, txtUnitPrice, lblTotalvalue).Text = "";
Run Code Online (Sandbox Code Playgroud)

Sim*_*son 9

你可以这样做:

txtUnitTotalQty.Text = txtPrice.Text = txtUnitPrice.Text = lblTotalvalue.Text = string.Empty;
Run Code Online (Sandbox Code Playgroud)

或者你可以为它编写一个方法:

public void SetText(params TextBox[] controls, string text)
{
    foreach(var ctrl in controls)
    {
        ctrl.Text = text;
    }
}
Run Code Online (Sandbox Code Playgroud)

使用方法是:

SetText(txtUnitTotalQty, txtPrice, txtUnitPrice, lblTotalvalue, string.Empty);
Run Code Online (Sandbox Code Playgroud)