0

What is the different when using string.IsNullOrEmpty and string = ''

If  string.IsNullOrEmpty(str) then
   ' do something
End If

If string = "" then
   ' do something
End If

Does IsNullorEmpty include ""?

1
  • 2
    yes - that is exactly what empty means. Commented Dec 30, 2014 at 4:11

2 Answers 2

1

The String.IsNullOrEmpty method checks for both null and empty fields, while string=="" only checks for empty fields.

If a string is not defined, it will be null by default. Therefore, it is a better idea to use IsNullOrEmpty.

P.S. 'a' and "a" is different. The single quote is used for characters while double quotes are used for strings.

Sign up to request clarification or add additional context in comments.

Comments

1

This is a good reference for the built-in function IsNullorEmpty of the String class:

http://msdn.microsoft.com/en-us/library/system.string.isnullorempty(v=vs.110).aspx

The difference is that the latter uses a built-in function to return True or False in checking strings if they are empty. Basically the second condition is a straight-forward checking of a String if it is empty.

IsNullorEmpty does not include " in its syntax. Hope that helps.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.