- Home /
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)
Answer by rutter · Jun 04, 2012 at 08:56 PM
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.
thanks, it works. but that shouldn't be needed though:
it looks like it may have something to do with the $$anonymous$$ono compiler then.
Your answer
![](https://koobas.hobune.stream/wayback/20220613072343im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Distribute terrain in zones 3 Answers
Multiple Cars not working 1 Answer
How to serialize a concrete derived class from generic ScriptableObject base 1 Answer
An OS design issue: File types associated with their appropriate programs 1 Answer
When will Unity Support .NET 4 to the current Mono Level? 1 Answer