65.9K
CodeProject is changing. Read more.
Home

Best practices in developing ASP.NET applications

starIconstarIconstarIconstarIconstarIcon

5.00/5 (1 vote)

Jan 19, 2011

CPOL
viewsIcon

10395

I agree with Chris...string.IsNullOrEmpty: 312 msLength: 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...

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.