Generic method where T is type1 or type2

后端 未结 7 1872
陌清茗
陌清茗 2021-02-12 01:58

Is there a way to declare a generic function that the generic type is of type1 or type2?

example:

public void Foo(T number)
{
}         


        
7条回答
  •  抹茶落季
    2021-02-12 02:11

    No.

    That doesn't make sense; T would not have any usable compile-time type in the method.

    Instead, you should make two overloaded methods.

提交回复
热议问题