typeof

  • Thread starter Thread starter boxim
  • Start date Start date
B

boxim

hi all,

If i've got an object which is of type MyTextBox which is derived from
System.Windows.Forms.TextBox, then in another class i want to check the type
of the control passed to one if methods, i.e

public void DoSomethingWithControl(System.Windows.Forms.Control _control) {

if (_control.GetType()==typeof(System.Windows.Forms.TextBox) {

// will not be true if i pass my object derived from
TextBox - not of type TextBox. How do i compare derived types?

}
}

TIA

Sam Martin
 
boxim said:
hi all,

If i've got an object which is of type MyTextBox which is derived from
System.Windows.Forms.TextBox, then in another class i want to check the type
of the control passed to one if methods, i.e

public void DoSomethingWithControl(System.Windows.Forms.Control _control) {

if (_control.GetType()==typeof(System.Windows.Forms.TextBox) {

// will not be true if i pass my object derived from
TextBox - not of type TextBox. How do i compare derived types?

I think you can simply check
if (_control is System.Windows.Forms.TextBox)
 
Back
Top