[Solved] If statement always returns true c# [closed]


Trying to work out the requirements, I reckon that what you want is:

If the target is Limited(), then fail if either we are larger than the capacity, or if there is not enough space in the target to add our amount

So, that would make the condition:

if (link.target.Limited()
 && (link.target.capacity < link.amount
       || link.target.amount + link.amount > link.target.capacity))

To be more symmetric, by swapping the LHS and RHS of the third expression this can be written as:

if (link.target.Limited()
 && (link.target.capacity < link.amount
  || link.target.capacity < link.target.amount + link.amount))

Now, we can further see that link.target.capacity < link.amount is true if and only if link.target.capacity < link.target.amount + link.amount is also true, so we can simplify to:

if (link.target.Limited()
 && link.target.capacity < link.target.amount + link.amount)

solved If statement always returns true c# [closed]