我通常动态调用类方法而没有问题,但只有这种方法不起作用,总是返回错误:
Dynamic conn = Activator.CreateInstance(Type.GetTypeFromProgID("MyTeam.MyClass"));
bool test = false;
conn.MyFunction(100,"test",DateTime.Now, test, test, "another","another","another");
使用VB的外部类的原始方法:
Public Function MyFunction(ByVal Id As Integer, ByVal Var1 As String, ByVal Fecha As Date,
Optional ByRef Opcion1 As Boolean = False,
Optional ByRef Opcion2 As Boolean = False,
Optional ByVal Var1 As String = "",
Optional ByVal Var2 As String = "",
Optional ByVal Var3 As String = "" ) As String
问题1:是否可以省略可选参数?
问题2:是否可以通过其他方式调用ByRef参数?
更新1:是的,C#支持ref / out参数,但......类型为“dynamic”的变量调用Method,是否支持这种类型的输入?
答案 0 :(得分:1)
为了在c#中传递byref,当你调用函数时,你需要在ref
之前加上参数。
conn.MyFunction(100,"test",DateTime.Now, ref test, ref test, "another","another","another");