Is there a way to declare a generic function that the generic type is of type1 or type2?
example:
public void Foo<T>(T number)
{
}
Can I constraint T to be int or long
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Although you could use a generic constraint to limit the type of each generic argument T, unfortunately there is none that would allow you to enforce at compile time whether T is
type1 or type2.Nor is there any way to enforce at compile time that your generic argument can only be of any primitive type (int, long, double, …).