.NET反射:如何通过返回返回对象数组的方法调用方法?

raj*_*lai 1 .net reflection

有一个快速的问题..谷歌搜索但没有任何值得找到..

我有一个简单的类型,如下所示.

public class DummyClass
{
    public string[] Greetings()
    {
         return new string[] { "Welcome", "Hello" };
    }
}
Run Code Online (Sandbox Code Playgroud)

如何通过反射调用"问候"方法?请注意,该方法返回字符串数组.

Jef*_*Cyr 11

调用这种方法没有什么特别之处:

object o = new DummyClass();

MethodInfo method = typeof(DummyClass).GetMethod("Greetings");
string[] a = (string[])method.Invoke(o, null);
Run Code Online (Sandbox Code Playgroud)