© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•4y ago•
12 replies
Star

How to call a static method form interface in a generic class.

So I have a class as bellow.
public interface ISetup<T, P> where T : class {
    public static T /*.*/ Setup(T target, P args) {
        return target;
    }
}
public interface ISetup<T, P> where T : class {
    public static T /*.*/ Setup(T target, P args) {
        return target;
    }
}


and then a second generic class.
public class ClassName<T, P> where T : class, ISetup<T, P>, new() {
    public T MethodName(P setupArg) {
        var holder = new T();
        return ISetup<T, P>.Setup(holder, setupArg);
    }
}
public class ClassName<T, P> where T : class, ISetup<T, P>, new() {
    public T MethodName(P setupArg) {
        var holder = new T();
        return ISetup<T, P>.Setup(holder, setupArg);
    }
}


but I am getting the error.
https://learn.microsoft.com/en-us/dotnet/csharp/misc/cs0704?f1url=%3FappId%3Droslyn%26k%3Dk(CS0704)

The problem is I can't directly call the type from a generic. Is there anyway to do this, or am I trying to do something C# just can't do?
Compiler Error CS0704
Compiler Error CS0704
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

❔ How to call static virtual interface method without completely reimplementing in derived class
C#CC# / help
3y ago
❔ generic class in generic method
C#CC# / help
3y ago
❔ Can i not call a non static Method in a interface?
C#CC# / help
3y ago