我在代码中动态加载了一个dll
Assembly.EmrAssembly=Assembly.LoadFrom(@"d:\test.dll");
Type typ = EmrAssembly.GetType("nameSp1.nameSp2.Class1");
object obj = Activator.CreateInstance(typ);
我要调用的方法ShowMsg()具有多个重载(如下):
ShowMsg(string msg);ShowMsg(string msg,int nID);ShowMsg(int nMsg,int nID);ShowMsg(string[] msgs);
请问我如果希望调用ShowMsg(int nMsg,int nID);这个重载应该怎样写?

解决方案 »

  1.   

    重载是方法名称相同,参数个数和类型不同来区分的.如果你想调用ShowMsg(int nMsg,int nID);你只需要传递两个int型的参数,系统会自动去调用带有两个int型参数的方法重载版本
      

  2.   

    推荐一本书:<C#入门经典>看看,多写写代码.
      

  3.   

        public class A
            {
                    private string returnString;
                    public string ReturnString
                    {
                            get { return returnString ; }
                            set { returnString = value ;}
                    }
     
                    public A()
                    {
                    }
     
                    public A(string str )
                    {
                            this.returnString = str;
                    }
     
                    public void FunctionWithoutParameter()
                    {
                            Console.WriteLine( "Without Parameter" );
                    }
     
                    public void FunctionWithParameter( string str )
                    {
                            Console.WriteLine( str );
                    }
            }
     object o = Activator.CreateInstance( type );
     MethodInfo mi = type.GetMethod("FunctionWithoutParameter" );
     mi.Invoke( o , null );object o = Activator.CreateInstance( type );
    MethodInfo mi = type.GetMethod( "FunctionWithParameter" ,BindingFlags.Public|BindingFlags.Instance,null , new Type[]{ typeof(string) } , null );
    mi.Invoke( o , new object[]{""} );
                         
      

  4.   

    CreateInstance也有多个重载,你只需要根据你的函数的参数类型,用CreateInstance传递就行了public static Object CreateInstance (
    Type type,
    params Object[] args//参数数组
    )