Check property

  • Thread starter Thread starter shapper
  • Start date Start date
S

shapper

Hello,

Before I add a control I need to check if its CssClass is defined.
Should I use:

If String.IsNullOrEmpty(MyControl.CssClass) Then
....

I am not sure if this is the correct way because the user can set my
mistake MyControl.CssClass = ""

How should I do it?

Thanks,
Miguel
 
Hello,

Before I add a control I need to check if its CssClass is defined.
Should I use:

If String.IsNullOrEmpty(MyControl.CssClass) Then
...

I am not sure if this is the correct way because the user can set my
mistake MyControl.CssClass = ""

How should I do it?

Thanks,
Miguel

Hi

When MyControl.CssClass = "", the method
String.IsNullOrEmpty(MyControl.CssClass) will return true because the
string is Empty i.e. the property references a string object which has
zero characters (zero length). This is not the same as being Null (or
rather Nothing in VB) when the reference itself is null and the string
object doesn't exist. As the method name implies it returns true in
either case so is a useful way to tell if the CssClass is defined or
not.
 
Back
Top