2 つの変数を使用する最善の方法について、簡単な質問があります。基本的に、いくつかの if 内で取得したい値である enum と int があります。if の外側または内側で宣言する必要があります。次の例を検討してください。
エガ:
public void test() {
EnumName? value = null;
int distance = 0;
if(anotherValue == something) {
distance = 10;
value = getValue(distance);
}
else if(anotherValue == somethingElse) {
distance = 20;
value = getValue(distance);
}
if (value == theValueWeWant){
//Do something
}
また
例2
public void test() {
if(anotherValue == something) {
int distance = 10;
EnumType value = getValue(distance);
if (value == theValueWeWant){
//Do something
}
else if(anotherValue == somethingElse) {
int distance = 20;
EnumType value = getValue(distance);
if (value == theValueWeWant){
//Do something
}
}
私はちょうど興味がありますか?またはより良い方法がある場合は?