© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•3y ago•
14 replies
nut

❔ generic class in generic method

im trying to have this method:
        public void AddPrefab<T, C>(C args) where T : Prefab<C> where C : PrefabArgs
        {
            T.Create(this, args);
        }
        public void AddPrefab<T, C>(C args) where T : Prefab<C> where C : PrefabArgs
        {
            T.Create(this, args);
        }

where each thing that inherits Prefab has a PrefabArgs generic type thing, like, a Prefab "player" could be Player<PlayerPrefabArgs>, and you can call this method like
AddPrefab<Player>(new PlayerPrefabArgs());
AddPrefab<Player>(new PlayerPrefabArgs());

but the problem im having is this just isnt working how id like it to, i have to do
AddPrefab<Player, PlayerPrefabArgs>(...);
AddPrefab<Player, PlayerPrefabArgs>(...);

like it doesnt know how to infer the type or something
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

without generic class can i create generic method or generic field?
C#CC# / help
4y ago
Generic Class Help
C#CC# / help
3y ago
❔ Using method in other class
C#CC# / help
3y ago
How to call a static method form interface in a generic class.
C#CC# / help
4y ago