views:

30

answers:

1

Assume I have a Listbox with two types of objects in it, either a String, or a custom class called "Label".

When I'm drawing the items in the listbox, is there a way to determine whether to cast e as a string or "label"?

The functionality I'm looking for is so that the Strings show up as one color, and the Labels show up as another. (Part of the Label Class being that they have their own color value to be extracted and then used)

+1  A: 

Just test the objects for their type.

if (e is String)
{
    //do something..
}
else if (e is Label)
{
    //do something..
}
jsmith
d'oh. "is" makes a lot more sense than "typeof". Much obliged.
Raven Dreamer