Click here to Skip to main content
Click here to Skip to main content

Best practices in developing ASP.NET applications

By , 19 Jan 2011
 
I agree with Chris...
 
string.IsNullOrEmpty:   312 ms
Length:                 140 ms  [fastest]
 
This is not a fair comparison.
 
Need to compare:
(string != null && string.Length !=0)
with:
String.IsNullOrEmpty(string)
Even if the first construct is faster, there is a readability factor:
 
if (!String.IsNullOrEmpty(someString)) {
//do something with someString
...
}
or:
if (someString != null && someString.Length != 0) {
//do something with someString
...
}
The second construct becomes increasingly ugly if there is more than one string to deal with.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

_impostor_
Web Developer
Australia Australia
Member
No Biography provided

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
Hint: For improved responsiveness ensure Javascript is enabled and choose 'Normal' from the Layout dropdown and hit 'Update'.
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
General@Deeksha Shenoy: The best practice is whenever your are usin...memberMahendra Vishwakarma30 Jan '11 - 20:45 
@Deeksha Shenoy: The best practice is whenever your are using string variable, you have to initialize it with empty value...like someString="";
GeneralHi, As u said string.IsNullOrEmpty is taking 312 ms. I real...membersendtodilip24 Jan '11 - 18:42 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Permalink | Advertise | Privacy | Mobile
Web04 | 2.6.130516.1 | Last Updated 19 Jan 2011
Article Copyright 2011 by _impostor_
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid