私はこの次のコードを持っている:このコードを最適化するにはどうすればよいですか?
if (userValueSom01 == realResult01)
{
//answer = correct
//count +1 for overall good answers
WpfApplication1.Properties.Settings.Default.totallGood++;
//count for good +1
answerThisWindowGood++;
//make visible the green logo
Som01G.Visibility = Visibility.Visible;
}
else
{
//answer = wrong
//count +1 for overall wrong answers
WpfApplication1.Properties.Settings.Default.totallWrong++;
//count for wrong +1
answerThisWindowWrong++;
//make visible the red logo
Som01W.Visibility = Visibility.Visible;
labelSom01Check.Content = Convert.ToString(realResult01);
}
今ポイントであるが、これはXXはあなたがコード内で参照番号に対応する番号であるXX回、発生します。 上記の例では、XXは01です。 *入力には01が、結果には01も入ります
C#(まだ)にはまだ深くありません。 XXは20、私はこれを上記の部分を20回コピーして番号を変更する必要があります。 これは扱いにくいようですが、これに対処するにはよりスマートな方法が必要ですね、ポイントは、(上記のように、私はまだC#には深くない)方法を考えることができません。
私を正しい方向に押し込むことができる人はいますか?
ありがとうございます。
---あなたのソリューションとは若干異なるEDIT 1 --- ありがとうMiika L. :
public bool checkValue(double value, int result, Image controlG, Image controlW, Label label)
{
if (value == result)
{
//... Do stuff
controlG.Visibility = Visibility.Visible;
return true;
}
else
{
//... Do other stuff
controlW.Visibility = Visibility.Visible;
label.Content = result.ToString();
return false;
}
}
を、今私は実際にちょうど呼び出すことができます。 ブールテスト= checkValue(userValueSom01、realResult01、 Som01G、Som01W、labelSom01Check);
作品: ありがとう!
上記のコードから、多くの最適化を行うことはできません。あなたはxx回(1つのカウンタで記録する)、次にカウンタ(カウンタで)で値を設定します。 –
ahaa、繰り返しで値を++にしますか? – Dante1986