33

What is the syntax for placing constraints on multiple types? The basic example:

class Animal<SpeciesType> where SpeciesType : Species

I would like to place constraints on both types in the following definition such that SpeciesType must inherit from Species and OrderType must inherit from Order:

class Animal<SpeciesType, OrderType>

2 Answers 2

60
public class Animal<SpeciesType,OrderType>
    where SpeciesType : Species
    where OrderType : Order
{
}
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks! i always forget this if I do not write it often!
18

You should be able to go :

class Animal<SpeciesType, OrderType>
    where SpeciesType : Species
    where OrderType : Order {
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.