Sunday, 13 February 2011
5 Wrong ways to check empty strings
Do you like this story?
It is one of the common mistake that people compare a string with “” or String.Empty in VB.Net or C# to find its empty. Here are few examples.
// C# Wrong WaysSo what’s the correct way to do it ? Check for length too.
- if ( s == “” )
- if ( s == string.Empty )
- if ( s.Equals(”") )
- if ( s.Equals ( String.Empty)
- if ( string.Equals(s,”")
- if ( string.Equals ( s,String.Empty ))
// [ C# ] Correct Wayif ( s.Length == 0 )
This post was written by: Rishabh Dangwal
Rishabh Dangwal is a no-nonsense network geek who likes to play retro games and emulators in free time. Follow him on Twitter
Subscribe to:
Post Comments (Atom)
0 Responses to “5 Wrong ways to check empty strings”
Post a Comment