string.Length < 1 : Is this right?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,
Which one of these below two is a better way to find out if the string is of
zero length?

string.Length == 0
or
string.Length < 0

Alwin S.
 
Well the first is clearer although I prefer

s == string.Empty

What do you mean by "better"? If you mean in terms of performance then in any application, this sort of micro-optimization is irrelevent. Write the code with clarity, performance test the application and if there are issues, profile the aplication and find out where the real bottlenecks are.

Regards

Richard Blewett - DevelopMentor
http://www.dotnetconsult.co.uk/weblog
http://www.dotnetconsult.co.uk

nntp://news.microsoft.com/microsoft.public.dotnet.languages.csharp/<[email protected]>

I meant...

string.Length == 0
or
string.Length < 1
 
Al,
I tend to use <1 where applicable, since I program in several languages that
are not all compatable in thier return values. In this case Length cannot be
< 0, but that is not the case for length in everything I use.
 
Back
Top