Possible Duplicate:
Can’t operator == be applied to generic types in C#?
I have a DatabaseLookup{} class where the parameter T will be used by the lookup methods in the class. Before lookup, I want to see if T was already looked up with something like
if (T == previousLookupObject) ...
This doesn’t compile at all. What is preventing me from making a simple comparison like this?
Tis the type parameter. If yourpreviousLookupObjectis an object ofType, you need to dotypeof(T) == previousLookupObject.If
previousLookupObjectis variable of typeT, you need to have an actual object ofTto compare it to.If you want to find out if
previousLookupObjectis of typeT, you need to use theisoperator:if (previousLookupObject is T).