Which is more efficient for the compiler and the best practice for checking whether a string is blank?
- Checking whether the length of the string == 0
- Checking whether the string is empty (strVar == "")
Also, does the answer depend on language?
Answer
Yes, it depends on language, since string storage differs between languages.
- Pascal-type strings:
Length = 0
. - C-style strings:
[0] == 0
. - .NET:
.IsNullOrEmpty
.
Etc.
No comments:
Post a Comment