Jump to content
  • Advertisement
Sign in to follow this  
Lucidquiet

[.net] Multiple generic parameters multiple constraints

This topic is 4176 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
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!