Check property

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
 
P

Phil H

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,773
Messages
2,569,594
Members
45,121
Latest member
LowellMcGu
Top