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 Way
if ( s.Length == 0 )
Perfect Coding...
ReplyDelete