Thanks to Michal Boleslav Mechura, who pointed me back to Jeffrey Richter's "Applied Microsoft .NET Framework Programming" on this.
Basically whenever you do an “is“ comparison for decision making, for example
if( _control is TextBox)
{
// do your stuff
}
else
{
// do other stuff
}
there is a cast thru “as“ done anyways. This is nothing new.
The delay comes when you do this
if( _control is TextBox)
{
TextBox _textbox = (TextBox)_control;
}
else
{
// do other stuff
}
Notice that you are doing the type cast again. For this case, it is better to do this
TextBox _textbox = _control as TextBox;
if(_textbox != null)
{
// do your stuff
}
else
{
// do other stuff
}
Posted
Mon, Jan 24 2005 7:40 AM
by
rsakalley