Click here to Skip to main content
11,478,562 members (64,568 online)
Click here to Skip to main content

Tagged as

Check for empty string using length property of the string variable

, 23 Jun 2010 CPOL 4.5K
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 Thumbs Up | :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

Comments and Discussions

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

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

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

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