Click here to Skip to main content
12,889,951 members (45,990 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as


Posted 23 Jun 2010

Check for empty string using length property of the string variable

, 23 Jun 2010 CPOL
Rate this:
Please Sign up or sign in to vote.
Most of the developers use string.Empty to check the empty string. Instead we can check and compare the length property is zero to know the string value is empty or not.
This will increases the performance :thumbsup:


string empName = txtEmployeeName.Text;

if(empName.Length <= 0)
Response.Write("Employee name is empty");


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Software Developer HCL Technologies Limited
India India
No Biography provided

You may also be interested in...


Comments and Discussions

GeneralReason for my vote of 2 This is good trick if you don't care... Pin
mazaaz24-Jun-10 1:05
membermazaaz24-Jun-10 1:05 
QuestionWhay if a string is null? Pin
Ankur\m/23-Jun-10 3:40
memberAnkur\m/23-Jun-10 3:40 
AnswerRe: Whay if a string is null? Pin
Prakash.LE23-Jun-10 20:03
memberPrakash.LE23-Jun-10 20:03 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170424.1 | Last Updated 23 Jun 2010
Article Copyright 2010 by Prakash.LE
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid