Last active
October 24, 2015 08:21
-
-
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()
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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