문제

I have a boolean dupe which determines whether two month/year selections are the same... and assigns the appropriate true/false accordingly.

Sometime thereafter, once a certain action is acted upon, dependent on whether dupe is true or not, dupe is turned off (made false)...

I have the following:

dupe = (dupe)?false:dupe;

Which seems fine and I know that works, but I have this weird feeling that it could be made simpler... am I imagining things, or is there a better way of doing this?

I've been staring at this for the good part of ten minutes, and I would rather have an answer than go insane... so can someone please set me straight?

Thanks.

도움이 되었습니까?

해결책

You want this:

dupe = !dupe || false;

However, note that if

dependent on whether dupe is true or not, dupe is turned off

You are setting dupe to false if it's true, and false if it's false, that means it's always going to be false.

So you might as well do this:

dupe = false;

다른 팁

if(dupe){
   dupe =false;
}else{
   dupe=dupe
}

so basically

you are setting dupe=false; whether it is false or true

so you should place dupe= false;

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top