Calling a function using reflection that has a “params” parameter (MethodBase)

前端 未结 3 1495
Happy的楠姐
Happy的楠姐 2020-12-11 15:40

I have MethodBases for two functions:

public static int Add(params int[] parameters) { /* ... */ }
public static int Add(int a, int b) { /* ... */ }
<         


        
3条回答
  •  没有蜡笔的小新
    2020-12-11 15:54

    You should wrap the arguments in an array, but the compiler will be confused, so you need to help it a bit:

    Eg:

    AddMethod.call((object) new int[] {5, 4 });
    

提交回复
热议问题