Before updating to Windows 10 you may need to return your Pro license. More information here

C# generics: using class generic in where clause of method generic

Why isn't this supported in Unity?

 public class Container<T>
     private static class PerType<U> where U : T
         public static U item;
     public U Get<U>() where U : T
         return PerType<U>.item;
     public void Set<U>(U newItem) where U : T
         PerType<U>.item = newItem;

I'm getting this error:

error CS0305: Using the generic type Container.PerType' requires2' > type argument(s)

more ▼

asked Jun 04, 2012 at 08:26 PM

avatar image

413 61 64 51

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

If you replace PerType<U> with Container<T>.PerType<U> on lines 10 and 15, it will at least compile. Could be that the compiler is having difficulty resolving a generic class that's nested within another generic class.

more ▼

answered Jun 04, 2012 at 08:56 PM

avatar image

17.3k 3 19 56

thanks, it works. but that shouldn't be needed though:


it looks like it may have something to do with the Mono compiler then.

Jun 05, 2012 at 09:05 AM andresp
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments



asked: Jun 04, 2012 at 08:26 PM

Seen: 2288 times

Last Updated: Jun 08, 2012 at 01:45 PM