C#中反射调用带out参数的方法

using System;
using System.Reflection;

namespace ConsoleApplication1
{
    public class TestAssembly
    {
        public TestAssembly()
        {
            String str = "aa";
            object[] parmsObj = new object[] { str };

            Assembly assembly = Assembly.GetExecutingAssembly();
            Type actionType = assembly.GetType("ConsoleApplication1.TestClass");
            MethodInfo method = tp.GetMethod("test", new Type[] { Type.GetType("System.String&") });
            object obj = Activator.CreateInstance(actionType.FullName);
            method.Invoke(obj, parmsObj);
            Console.WriteLine(parmsObj[0]);
        }
    }


    public class TestClass
    {
        public void test(out string str)
        {
            str = "test1";
        }

        public void test(string str)
        {
            str = "test2";
        }
    }
}

链接资源: http://support.microsoft.com/default.aspx?scid=kb%3bzh-cn%3b815211 

posted on 2007-11-09 14:31  IORICC  阅读(1879)  评论(0编辑  收藏  举报