Click here to Skip to main content
Click here to Skip to main content

Tagged as

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 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... Pinmembermazaaz24-Jun-10 2:05 
QuestionWhay if a string is null? PinmemberAnkur\m/23-Jun-10 4:40 
AnswerRe: Whay if a string is null? PinmemberPrakash.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
Web01 | 2.8.150414.1 | Last Updated 23 Jun 2010
Article Copyright 2010 by Prakash.LE
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid