Assume I have a Listbox with two types of objects in it, either a String, or a custom class called "Label".
When I'm dr开发者_高级运维awing 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)
Just test the objects for their type.
if (e is String)
{
//do something..
}
else if (e is Label)
{
//do something..
}
精彩评论