Allow out
, in
, and ref
in generic type parameters.
#7839
-
Currently, generics don't support public delegate TOutput RefFunc<TInput, TOutput>(ref TInput param); I propose that this limitation be lifted so that one could write int x = 0;
Test<ref int>(ref x);
void Test<T>(T param) { } The compiler would "fill in" the type parameters into the definition, and complain if something doesn't make sense. For example, the following would cause a compiler error: Func<out int> x; // error about usage of an "out" parameter in return position
Test<in int>(); // error about usage of an "in" parameter in return position
T Test<T>() => default(T)!; |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 1 reply
-
You can just define a different delegate type to support |
Beta Was this translation helpful? Give feedback.
-
There is a proposal for this already #5321 |
Beta Was this translation helpful? Give feedback.
-
We'd likely do this, if the runtime adds support for it. |
Beta Was this translation helpful? Give feedback.
There is a proposal for this already #5321