468,510 Members | 1,769 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,510 developers. It's quick & easy.

typeof

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.Contro l _control) {

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

// 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
Nov 15 '05 #1
1 14939


boxim wrote:
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.Contro l _control) {

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

// 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)

--

Martin Honnen
http://JavaScript.FAQTs.com/

Nov 15 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Eric | last post: by
4 posts views Thread by ichor | last post: by
3 posts views Thread by Alberto | last post: by
1 post views Thread by Brien King | last post: by
11 posts views Thread by Jason Kendall | last post: by
2 posts views Thread by Andrew Robinson | last post: by
20 posts views Thread by rkk | last post: by
reply views Thread by NPC403 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.