Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / web / HTML

Parse out controls from your html page.

5.00/5 (1 vote)
6 Nov 2011CPOL 4.7K  
Tip - Never use type equality because that does not support derived classes:if (item.GetType() == typeof(Image)) //this is bad, mkay.Instead use the following which does support derived classes:if (item is Image)The Microsoft prefered pattern (when you actually need the cast object)...

Tip - Never use type equality because that does not support derived classes:


SQL
if (item.GetType() == typeof(Image)) //this is bad, mkay.

Instead use the following which does support derived classes:


SQL
if (item is Image)

The Microsoft prefered pattern (when you actually need the cast object) is:


SQL
var itemAsType = item as Image;
if (itemAsType != null)

That way, you will only have to typecast once.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)