473,322 Members | 1,522 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,322 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 1781
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: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.