I’m a little confused by this interface and class definition. Could someone possibly shed some light?
The interface and a class that inherits from it are defined this way:
public abstract class DNum {
}
public abstract class DNum<DIM> : DNum where DIM : DNum<DIM> { //etc...
…the DIM : DNum<DIM> bit is throwing me. DIM has to inherit from the class we’re currently defining, with itself as a generics parameter? Is this some sort of infinitely-recursive definition? What’s going on here?
Polity’s link to Eric Lippert’s blog is very useful to undestand what might have been the intent of the author of these strange declarations.
Please note that (as long as the intent would be the one proposed by E. Lippert), there’s an alternate way of expressing the same kind of constraint, which is far more safe, readable and understandable.
It relies on expression methods.
Because your code sample is not enough clear to establish an intent, let’s suppose we’ve read Eric Lippert’s article and that the intent is to allow any kind of animal able to make friend only with another animal of the same breed.
Then you can do like that :
Knowing this technique is VERY useful (and not confusing at all).