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 ""?
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 ""?
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.
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.