About Equals Operator Overloading in Interface: What Constraint Does CS9046 Need? #7330
Answered
by
CyrusNajmabadi
Orange23333
asked this question in
Q&A
-
Problempublic interface IPathNode<TValue, TCoordinate> where TValue : IBinaryNumber<TValue> where TCoordinate : struct
{
Guid NId { get; }
public virtual static bool operator ==<TSelf>(TSelf left, TSelf right) where TSelf : IPathNode<TValue, TCoordinate>
{
return left.NId == right.NId;
}
public virtual static bool operator !=<TSelf>(TSelf left, TSelf right) where TSelf : IPathNode<TValue, TCoordinate>
{
return left.NId != right.NId;
}
}
Blob
I need help! |
Beta Was this translation helpful? Give feedback.
Answered by
CyrusNajmabadi
Jul 10, 2023
Replies: 1 comment 1 reply
-
the pattern this is looking for is something like: interface I<X> where X : I<X>
{
public virtual static operator ==(X x, ...)
} here, one of the parameters of the equality operator is a type parameter on I, (specifically |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
Orange23333
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
the pattern this is looking for is something like:
here, one of the parameters of the equality operator is a type parameter on I, (specifically
X
) and that type parameter itself is constrained toI<X>
.