- if(myString == String.Empty)
- if(myString == "")
- if(myString.Length == 0) - this could throw an exception if myString is null
- I also found this comparison: if( String.Equals(myString, String.Empty) )
- and of course method IsNullOrEmpty introduced in .Net Framework 2:
if(string.IsNullOrEmpty(myString)) which is said to be the most efficient.
Now, which methods do you use when comes to test if a string has a value or not? You are invited to write them as comments :) Of course that no matter which one of the methods above you choose won't slow down to much the performance of your application, but is good to build a good practice for future projects, isn't it?
Vezi ca string.IsNullOrEmpty este o metoda
ReplyDeleteif (string.IsNullOrEmpty(myString))
Thanks Ionut for your reply, this is what it happens when you don't verify the code :) I have changed now the post. Regards.
DeleteYou're welcome. Keep up the good work ;)
Delete