Method overloading based on generic constraints?

后端 未结 4 1419
甜味超标
甜味超标 2021-01-17 11:24

Can I somehow have overloaded methods which differ only by generic type constraints?

This does not compile:

    void Foo(T bar) wh         


        
4条回答
  •  一整个雨季
    2021-01-17 12:00

    Can I somehow have overloaded methods which differ only by generic type constraints?

    No. It's not part of the method signature in terms of overloading, just like the return type isn't.

    There are horrible ways of "pseudo-overloading" in some cases, but I wouldn't recommend going down that path.

    For more information, you might want to read:

    • My blog post on the topic
    • Eric Lippert's blog post on the topic

提交回复
热议问题