Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SauliusSun/4a087bc8a573c8fac99f to your computer and use it in GitHub Desktop.
Save SauliusSun/4a087bc8a573c8fac99f to your computer and use it in GitHub Desktop.
C# best practices: where possible use string object method IsNullOrWhiteSpace() instead of IsNullOrEmpty()
using System;
public class Program
{
static void Main()
{
string[] values = { null, "", " ", "val"};
foreach (string value in values)
{
// Use string object method IsNullOrWhiteSpace() instead of IsNullOrEmpty().
Console.WriteLine(string.IsNullOrWhiteSpace(value));
}
}
}
// The example displays the following output:
// True
// True
// True
// False
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment