Wrox Programmer Forums
Go Back   Wrox Programmer Forums > .NET > Other .NET > General .NET
General .NET For general discussion of MICROSOFT .NET topics that don't fall within any of the other .NET forum subcategories or .NET language forums.  If your question is specific to a language (C# or Visual Basic) or type of application (Windows Forms or ASP.Net) try an applicable forum category. ** PLEASE BE SPECIFIC WITH YOUR QUESTION ** When posting here, provide details regarding the Microsoft .NET language you are using and/or what type of application (Windows/Web Forms, etc) you are working in, if applicable to the question. This will help others answer the question without having to ask.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the General .NET section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old August 8th, 2004, 11:34 AM
Authorized User
Join Date: Mar 2004
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Default Checking for empty string

Under VB6 it's faster to check for zero string length than to check for equality to ""

if strDummy.Length < 1
is faster than
if strDummy = ""

Yet I find professionally written code that takes the slow route Is this still true under .NET? I suspect that it is.

Are there other pre .NET truisms that can be verified as applicable or not applicable under .NET? Is there a book on the subject?

Thanks for any help or opinions on the subject.

Richard Waddell

Old August 8th, 2004, 01:37 PM
planoie's Avatar
Friend of Wrox
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts

I just did a crude test of string test method comparisons:

10000000 iterations of 'strTestString = ""' completed in 78ms

10000000 iterations of 'strTestString.Length > 0' completed in 62ms

10000000 iterations of 'strTestString.Equals(String.Empty)' completed in 140ms

10000000 iterations of 'strTestString = String.Empty' completed in 328ms

I had to keep increasing the test count till I finally saw some results... started at about 10 million repeats. Given that, I think the method one uses for testing strings is really negligable compared of all the other things one can do to streamline a .NET application.

With the speed of computers, and the strength and speed of the .NET framework, it's probably a much better investment of time and money to study good design techniques. Poor design will have a much larger impact on everything than the nuances of syntax variations.

Similar Threads
Thread Thread Starter Forum Replies Last Post
Checking to see if a label's text is empty mh JSP Basics 2 October 26th, 2005 11:05 AM
Checking to see if a label's text is empty mh ASP.NET 2.0 Basics 2 October 26th, 2005 10:38 AM
Help checking for empty dataset Payback ASP.NET 1.0 and 1.1 Basics 5 March 28th, 2005 05:00 AM
checking for empty recordsets ! spraveens Classic ASP Databases 0 September 9th, 2003 10:18 PM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.