2010-05-24

C# Type safe casting and explicit casting

Explicit casting :
Label label = (
Label)e.FooterRow.FindControl("lblNAme");

if (label != null)
{
// Todo :

}

Type safe casting :
Label label = e.FooterRow.FindControl("lblNAme") as Label;
//'is' keyword is used in conjunction after 'as', to provide
//a more intuitive
then comparing to null as in explicit casting sample
if (label is Label)
{
// Todo :
}




ShareThis