0
我創建了一個函數(如下所示),將9個按鈕的文本全部分配給「」(我通常嘗試使用「」,而不是將一個變量分配給某個不合邏輯的假設,所以如果我不正確,我將不勝感激),但我覺得我可以用更簡潔的方式將每個參數分配給空白字符串。C#乾淨地爲每個方法參數分配一個值
public void resetText(ref string buttonText1, ref string buttonText2, ref string buttonText3, ref string buttonText4, ref string buttonText5, ref string buttonText6, ref string buttonText7, ref string buttonText8, ref string buttonText9)
{
buttonText1 = "";
buttonText2 = "";
buttonText3 = "";
buttonText4 = "";
buttonText5 = "";
buttonText6 = "";
buttonText7 = "";
buttonText8 = "";
buttonText9 = "";
}
是否有更簡潔的方法來重新分配每個參數。如果我不得不在這個函數中爲50個變量賦一個新的值(這裏我只是使用了按鈕作爲例子),這看起來相當糟糕。)
似乎沒有更乾淨的方法來做到這一點。但是,也許父函數可以通過將文本值保存在數組中來更好地實現這一點。 –
因此,你不知道只是循環遍歷所有參數併爲它們分配一個空值或類似的東西? –
可以更新爲:'buttonText1 = buttonText2 = buttonText3 = buttonText4 = buttonText5 = buttonText6 = buttonText7 = buttonText8 = buttonText9 = string.Empty; ' – zzT