code_junkie

What is the best practice concerning C# short-circuit evaluation?

Nov 12th, 2011
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.79 KB | None | 0 0
  1. if (String.IsNullOrEmpty(text1) | String.IsNullOrEmpty(text2) | String.IsNullOrEmpty(text3))
  2. {
  3. //...
  4. }
  5.  
  6. if (String.IsNullOrEmpty(text1) || String.IsNullOrEmpty(text2) || String.IsNullOrEmpty(text3))
  7. {
  8. //...
  9. }
  10.  
  11. bool nullorempty = str == null || str.Length == 0;
  12.  
  13. bool hasBuzzed = checkMakeBuzz();
  14. bool isFrobbed = checkMakeFrob();
  15. bool result = hasBuzzed || isFrobbed;
  16.  
  17. bool isPasswordValid = true;
  18.  
  19. isPasswordValid &= isEightCharacters(password);
  20. isPasswordValid &= containsNumeric(password);
  21. isPasswordValid &= containsBothUppercaseAndLowercase(password);
  22.  
  23. return isPasswordValid;
  24.  
  25. return (isEightCharacters(password) &&
  26. containsNumberic(password) &&
  27. containsBothUppercaseAndLowercase(password));
  28.  
  29. if (false & somethingThatUpdatesTheDatabase()) { /* ... */ }
Add Comment
Please, Sign In to add comment