Generic method multiple (OR) type constraint

前端 未结 4 593
无人及你
无人及你 2020-11-27 04:53

Reading this, I learned it was possible to allow a method to accept parameters of multiple types by making it a generic method. In the example, the following code is used wi

4条回答
  •  余生分开走
    2020-11-27 05:50

    That is not possible. You can, however, define overloads for specific types:

    public void test(string a, string arg);
    public void test(string a, Exception arg);
    

    If those are part of a generic class, they will be preferred over the generic version of the method.

提交回复
热议问题