473,396 Members | 1,815 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

string.Length < 1 : Is this right?

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.
Nov 16 '05 #1
8 1785
I meant...

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

"Al Sav" wrote:
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.

Nov 16 '05 #2
I meant...

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

"Al Sav" wrote:
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.

Nov 16 '05 #3
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/<A2**********************************@microsoft.co m>

I meant...

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

Nov 16 '05 #4
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/<A2**********************************@microsoft.co m>

I meant...

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

Nov 16 '05 #5
Les
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.

"Al Sav" wrote:
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.

Nov 16 '05 #6
Les
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.

"Al Sav" wrote:
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.

Nov 16 '05 #7
http://www.dotnet247.com/247referenc...23/118322.aspx

ShaneB

"Les" <Le*@discussions.microsoft.com> wrote in message
news:0B**********************************@microsof t.com...
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.

"Al Sav" wrote:
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.

Nov 16 '05 #8
http://www.dotnet247.com/247referenc...23/118322.aspx

ShaneB

"Les" <Le*@discussions.microsoft.com> wrote in message
news:0B**********************************@microsof t.com...
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.

"Al Sav" wrote:
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.

Nov 16 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

17
by: Karl Ebener | last post by:
Hi! I asked a similar question before but then changed everything to using char-Arrays instead of the string class, but I would rather not do this again. So, does anyone know of a...
0
by: Al Sav | last post by:
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.
33
by: genc_ymeri | last post by:
Hi over there, Propably this subject is discussed over and over several times. I did google it too but I was a little bit surprised what I read on internet when it comes 'when to use what'. Most...
2
by: ventos | last post by:
First of all, ive been trying to learn c++ for a couple of days ;) Problem i need to strip http links from string code: string replaceAll(string s, string f, string r) { unsigned int found...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.