According to FxCop's recommendation, use String.IsNullOrEmpty() is a good approach to check the String is empty or not.
Case 1:
//No goodCase 2:
strUsername != ""
//BetterCase 3:
strUsername.Length != 0
//The Best
!String.IsNullOrEmpty(strUsername)
Reason: Equals requires more MSIL instructions than the other two. Length will throw an exception is the string is null. IsNullOrEmpty has the same performance with Length but also takes care of the null problem.
Go here for more detail information and example.
Go here for more detail information and example.

0 Comments:
Post a Comment