|
-
August 28th, 2008, 12:44 PM
#1
Compare 2 generic types?
Say I have a generic class with a generic type T, and in some point (which occurs after the instance of the class was created, i.e. the T type is now concrete) I want to compare 2 T's, like the following:
Code:
public bool Remove(T info)
{
if (this.Count == 0)
return false;
if (head.Info == info)
{
head = head.Next;
this.Count--;
return true;
}
//etc...
}
I get a precompiled error:
Error 1 Operator '==' cannot be applied to operands of type 'T' and 'T' C:\Documents and Settings\Gerbi\Local Settings\Application Data\Temporary Projects\List\List.cs 33 17 MyList
(I want to compare the address of the two T's in the memory and not their content)
Is it possible to make such comparison? If so, what should I replace the following line to?
Code:
if (head.Info == info)
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|