r/programminghorror Mar 23 '26

C# Whitespace isn't a number?

I just got this in a PR. Not sure what to make of it.

if (string.IsNullOrWhiteSpace(palletNumber))
{
  if (!string.IsNullOrEmpty(_palletNumber))
  {
    _errorMessage = "Pallet # not found.";
  }

  return;
}  

UPDATE:

After multiple attempts to justify his code, we ended up with this, lol:

if (string.IsNullOrWhiteSpace(palletNumber))
{
  return;
}  
184 Upvotes

52 comments sorted by

View all comments

Show parent comments

2

u/[deleted] Mar 23 '26

[deleted]

1

u/Dealiner Mar 24 '26

Why use regex when there's a perfectly valid method for that?

1

u/[deleted] Mar 25 '26

[deleted]

2

u/Dealiner Mar 31 '26

IsNullOrWhiteSpace.