C#中反射调用带out参数的方法
2007-11-09 14:31
459 查看
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
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
相关文章推荐
- .NET/C#利用反射调用含ref或out参数的方法示例代码
- Unity C# 使用反射,利用字符串作为泛型参数调用泛型方法。
- 【C#基础】方法及其调用、构造方法、out与ref参数及其返回值、方法重载、静态方法等简单介绍
- c#方法中调用参数的值传递方式和引用传递方式,以及ref与out的区别
- c#方法中调用参数的值传递方式和引用传递方式,以及ref与out的区别
- C#通过反射调用泛型参数方法介绍
- c#方法中调用参数的值传递方式和引用传递方式,以及ref与out的区别
- 如何通过反射调用带有ref或者out的参数的方法[迁移]
- C#如何通过反射调用带有ref或者out的参数的方法
- C#,动态加载DLL,通过反射,调用参数,方法,窗体
- 利用反射调用方法时,处理ref,out参数需要注意的问题
- c# 反射Invoke调用方法获得out带出的值
- C#控制台基础 activator与invoke,利用反射调用一个类的无参数方法
- 【C#基础】方法及其调用、构造方法、out与ref参数及其返回值、方法重载、静态方法等简单介绍
- c#方法中调用参数的值传递方式和引用传递方式以及ref与out的区别深入解析
- C#反射得并调用方法(方法参数类型)
- 利用反射调用方法时,处理ref,out参数需要注意的问题(转)
- C# 反射调用带参数的重载的泛型方法
- c#方法中调用参数的值传递方式和引用传递方式,以及ref与out的区别
- C#控制台基础 activator与invoke,利用反射调用一个类的有参数方法