Type casting in c# using the string name of the object type

后端 未结 4 1997
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-05 19:42

I have the following code, should be easy to follow through

public class Foo
{
    public void FooHasAMethod()
    {
        Console.WriteLine(\"it is me, fo         


        
4条回答
  •  孤城傲影
    2021-01-05 20:16

    Type fooObjType = fooObj.GetType();
    MethodInfo method = fooObjType.GetMethod("FooHasAMethod");
    method.Invoke(fooObj, new object[0]);

提交回复
热议问题