Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

string.IsNullOrEmpty() vs string.NotNullOrEmpty()

Tags:

string

c#

.net

I'm curious if any developers use string.IsNullOrEmpty() more often with a negative than with a positive

e.g.

if (!string.IsNullOrEmpty()) 

This is how I use the method 99% of the time. What was the design decision for this?

like image 560
Chris S Avatar asked Apr 09 '09 13:04

Chris S


People also ask

Which is better IsNullOrEmpty or IsNullOrWhiteSpace?

The method IsNullOrWhiteSpace covers IsNullOrEmpty , but it also returns true if the string contains only white space characters. So its always better to use IsNullOrWhiteSpace than IsNullOrEmpty ?

What is string IsNullOrEmpty?

In C#, IsNullOrEmpty() is a string method. It is used to check whether the specified string is null or an Empty string. A string will be null if it has not been assigned a value. A string will be empty if it is assigned “” or String. Empty (A constant for empty strings).

What does string IsNullOrEmpty return?

The C# IsNullOrEmpty() method is used to check whether the specified string is null or an Empty string. It returns a boolean value either true or false.


1 Answers

Because "IsNullOrEmpty" is easier to understand than "NotNullOrEmpty". The latter could be interpreted as:

  1. It's not null and it's not empty
  2. It's not null or it is empty
like image 130
Kent Boogaart Avatar answered Oct 03 '22 00:10

Kent Boogaart