このコードを単純化する方法はありますか? 同じタイプの複数のオブジェクトに同じプロパティを設定したいだけです。これらのオブジェクトは、Windows 8 アプリの TextBoxes です。Array と foreach で何かできると思いますが、よくわかりません ありがとう
private void makeVisible(int x)
{
if (x == 1)
{
field2.Visibility = Visibility.Visible;
field3.Visibility = Visibility.Visible;
field4.Visibility = Visibility.Visible;
field6.Visibility = Visibility.Visible;
field8.Visibility = Visibility.Visible;
field9.Visibility = Visibility.Visible;
field11.Visibility = Visibility.Visible;
}
if (x == 0)
{
field2.Visibility = Visibility.Collapsed;
field3.Visibility = Visibility.Collapsed;
field4.Visibility = Visibility.Collapsed;
field6.Visibility = Visibility.Collapsed;
field8.Visibility = Visibility.Collapsed;
field9.Visibility = Visibility.Collapsed;
field11.Visibility = Visibility.Collapsed;
errorReporter.Visibility = Visibility.Collapsed;
}
}