Possible Duplicate:
Type Checking: typeof, GetType, or is?
So I am comparing a Control’s type and I thought I could do something like this.
if (control[0].GetType() is TSendForReview)
However, I get the following warning.
The given expression is never of the provided ('MyApp.Controls.TSendForReview') type
So if I switch it to this the warning goes away.
if (control[0].GetType() == typeof(TSendForReview))
What exactly does that warning mean and what is the difference between typeof and is while comparing control types.
GetTypereturns an instance ofSystem.Typeand this is never an instance ofTSendForReview. You probably want to useto see if the control is an instance of your type.
Your modified version gets the runtime type of the control and compares it to the type instance for
TSendForReview. This is not the same as using is since it must have the exact type, whereasiswill return true for a subtype ofTSendForReview.And why the warning?
Source: MSDN