473,320 Members | 1,976 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

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 15184


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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Eric | last post by:
I need to do the following but it doesn't compile if(typeof(listBox1.Items) == typeof(string)){ return; } typeof(listBox1.Items) doesn't work at all. My listBox has 2 types of items in...
4
by: ichor | last post by:
hi what is the use of the typeof keyword , and how does it differ from the GetType method. i found the GetType method useful but i fail to understand the use of the typeof method. i have tried...
7
by: Mark Miller | last post by:
I am using Reflection.Emit to dynamically build a class. A method of the class to be built requires a Parameter of type "Type". But I don't know how to use Emit to pass a call of "typeof()" to the...
3
by: Alberto | last post by:
Can somebody tell me why this typeof doesn't work? foreach (Control myControl in Controls) if (typeof(myControl) == "TextBox") ((TextBox)myControl).Text = string.Empty; Thank you very much
1
by: Brien King | last post by:
Ok, I have three classes (The example here is extremely simplified to illustrate the problem) like this: Public Class A Public Sub DoSomething(ByVal myClass) If TypeOf myClass IS A Then ' '...
11
by: Jason Kendall | last post by:
Why doesn't the new "IsNot" operator work in conjunction with 'Typeof'?
2
by: Andrew Robinson | last post by:
I am guessing there is a simple solution but given a type T, how can I check for nullability? how can I accomplish the following? bool nullable = typeof(int).IsNullable; // false bool...
4
by: EManning | last post by:
Using A2003. I've got an option group that has a number of check boxes. I have coding to clear the option group if the user wishes to cancel their choice. This coding also clears the rest of the...
20
by: effendi | last post by:
I am testting the following code in firefox function fDHTMLPopulateFields(displayValuesArray, displayOrderArray) { var i, currentElement, displayFieldID, currentChild, nDisplayValues =...
20
by: rkk | last post by:
Hi, Is there an equivalent typeof macro/method to determine the type of a variable in runtime & most importantly that works well with most known C compilers? gcc compiler supports typeof()...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.