Generic type as Generic Method Parameter in c#- Possible?

How would I go about correcting the example below (which won’t compile)? I’d like to constrain a generic method so that T is always a variant of a generic type. I understand why it might not be possible, but maybe there’s something I don’t know. Thanks for any help!

void DoSomething<T>(T obj) where T: AGenericClass<> {
	// Doing Something
}

Alternatively, is there any way to do this?:

void DoSomething(AGenericClass<> obj) {
	// Doing Something
}

Thanks!

You can do this:

    void DoSomething<T>(AGenericClass<T> obj) {
        // Doing Something
    }

Is that what you’re going for?

1 Like

Ha! that is awesome, and exactly what I’m looking for. Thanks!