Is there a reasonable approach to “default” type parameters in C# Generics?

前端 未结 5 989
日久生厌
日久生厌 2020-11-27 18:59

In C++ templates, one can specify that a certain type parameter is a default. I.e. unless explicitly specified, it will use type T.

Can this be done or approximated

5条回答
  •  借酒劲吻你
    2020-11-27 19:11

    Unfortunately C# does not support what you are trying to do. It would be a difficult feature to implement given that the default type for a parameter would have to adhere to the generic constraints and would most likely create headaches when the CLR tried to ensure type-safety.

提交回复
热议问题