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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top