The IS operator
-
Well here's a case of "Read the Flipping Manual", if ever I saw one! I spent ages trying to compare a control to a TextBox, mostly without success - I went through all manner of
.Equals()
,.GetType
,== anotherTextBox.GetType(),
and all I needed to do was use wasif (control is TextBox)!
Gahhh! Still, I'm interested to know what the compiler is doing, and why if (control == TextBox) generates an error - can anyone illuminate me? Thanks, Martin. -
Well here's a case of "Read the Flipping Manual", if ever I saw one! I spent ages trying to compare a control to a TextBox, mostly without success - I went through all manner of
.Equals()
,.GetType
,== anotherTextBox.GetType(),
and all I needed to do was use wasif (control is TextBox)!
Gahhh! Still, I'm interested to know what the compiler is doing, and why if (control == TextBox) generates an error - can anyone illuminate me? Thanks, Martin. -
Well here's a case of "Read the Flipping Manual", if ever I saw one! I spent ages trying to compare a control to a TextBox, mostly without success - I went through all manner of
.Equals()
,.GetType
,== anotherTextBox.GetType(),
and all I needed to do was use wasif (control is TextBox)!
Gahhh! Still, I'm interested to know what the compiler is doing, and why if (control == TextBox) generates an error - can anyone illuminate me? Thanks, Martin.Utini wrote:
why if (control == TextBox) generates an error - can anyone illuminate me?
Because it's suppose to be:
control.GetType()==typeof(TextBox)
-
Well here's a case of "Read the Flipping Manual", if ever I saw one! I spent ages trying to compare a control to a TextBox, mostly without success - I went through all manner of
.Equals()
,.GetType
,== anotherTextBox.GetType(),
and all I needed to do was use wasif (control is TextBox)!
Gahhh! Still, I'm interested to know what the compiler is doing, and why if (control == TextBox) generates an error - can anyone illuminate me? Thanks, Martin.Utini wrote:
Well here's a case of "Read the Flipping Manual", if ever I saw one!
Exactly, RTFM. Your code
if( control == TextBox)
does not and should not compile for several reasons. 1)TextBox
is meaningless by itself.typeof(TextBox)
means something. 2) Assuming you use the code provieded (1), it is meaningless to check for equality between a Control and a Type. What on Earth would that mean? Josh -
Well here's a case of "Read the Flipping Manual", if ever I saw one! I spent ages trying to compare a control to a TextBox, mostly without success - I went through all manner of
.Equals()
,.GetType
,== anotherTextBox.GetType(),
and all I needed to do was use wasif (control is TextBox)!
Gahhh! Still, I'm interested to know what the compiler is doing, and why if (control == TextBox) generates an error - can anyone illuminate me? Thanks, Martin. -
Utini wrote:
why if (control == TextBox) generates an error
What error is it generating? Mike Poz
The error would be
'TextBox' is a 'type' but is used like a 'variable'
Scottish Developers events: * .NET debugging, tracing and instrumentation by Duncan Edwards Jones and Code Coverage in .NET by Craig Murphy * Developer Day Scotland: are you interested in speaking or attending? My: Website | Blog
-
Well here's a case of "Read the Flipping Manual", if ever I saw one! I spent ages trying to compare a control to a TextBox, mostly without success - I went through all manner of
.Equals()
,.GetType
,== anotherTextBox.GetType(),
and all I needed to do was use wasif (control is TextBox)!
Gahhh! Still, I'm interested to know what the compiler is doing, and why if (control == TextBox) generates an error - can anyone illuminate me? Thanks, Martin.control is an instance, TextBox is a type. Apples and oranges (or more correctly, cookies and cookie cutters).
Try code model generation tools at BoneSoft.com.