重新考虑if和else之间的公共代码if

use*_*762 2 c# c#-4.0

我有一个if ... else if语句如下:

  If(x > y && order.invoice != 1)
    {
       DoSomething();
       x = x + y;
    }
     else if(order.invoice == 1)
     {
       x = x + y;
     } 
Run Code Online (Sandbox Code Playgroud)

有没有更好的方法来重新考虑这一点.在if和else if中,我感觉不太好x = x + y.

Blo*_*ard 5

if (order.invoice != 1 && x > y) {
    DoSomething();
}
if (order.invoice == 1 || x > y) {       
   x = x + y;
}    
Run Code Online (Sandbox Code Playgroud)