Nested generics <T1 <T2>>

Why is it impossible to write something like this:

T1<T2> Method<T1, T2>(T1<T2> genericValue) { ... }

For example, I want to write an extension method that accepts a shared object containing shared code:

Container<CT<T>> ExtensionMethod<CT, T>(Container<CT<T>> value) { ... }

where CT can be an array, list, or any other type of collection, and T any type. But the compiler says: "T1 parameter type has no type parameters."

Is there any workaround for this?

+4
source share
1 answer

It's impossible. Your general should compile for anyone T. Therefore, if you make any assumptions about T, besides what it is object, you need to add restrictions with where .

. , , T . , , .

, , , , .

, , -, . , XY.

+7

Source: https://habr.com/ru/post/1680292/


All Articles