• Advertisement
Sign in to follow this  

[.net] Multiple generic parameters multiple constraints

This topic is 3900 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Does anyone know how to do multiple new() constraints on a class that has multiple parameter type? For instance: class MyClass<T, U> where T : new() and U : new() { } The problem is that you can only have a new constraint and it must be the last constraint, so if you have to generic parameters and they can both be constrained by the new() constraint, but only 1 can be last... get me? Does anyone know how to do this? L-

Share this post


Link to post
Share on other sites
Advertisement
Yup, that did it... I think I was trying to do too much at once, because I was also trying to extend a class, and I think I just put the ':' in the wrong place like this:

class MyClass<T,U> : SuperClass : where T : new() ':' where U : new() {}

or something like that.

What you provided worked... it's the simple things.

L-

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement