Chinaunix首页 | 论坛 | 博客
  • 博客访问: 195388
  • 博文数量: 52
  • 博客积分: 2010
  • 博客等级: 大尉
  • 技术积分: 570
  • 用 户 组: 普通用户
  • 注册时间: 2007-09-09 22:20
文章分类

全部博文(52)

文章存档

2009年(9)

2008年(27)

2007年(16)

我的朋友

分类: WINDOWS

2008-04-20 01:11:22

ClassLibrary1.cs
 
using System;
using System.Collections.Generic;
using System.Text;
 
namespace ClassLibrary1
{
    public class Class1
    {
        public void hello(String name)
        {
            Console.WriteLine("hello {0}",name);
        }
    }
}
 
csc /target:library ClassLibrary1.cs
 
================================================================
 
ConsoleApplication1.cs
 
using System;
using System.Collections.Generic;
using System.Text;
using System.Reflection;
namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            Assembly ass = Assembly.Load("ClassLibrary1");
           
            Type[] ts = ass.GetTypes();
            String classname = ts[0].FullName;
            MethodInfo[] methodnames = ts[0].GetMethods();
            String methodname = methodnames[0].Name;
            object o = ass.CreateInstance(classname);
            MethodInfo mi = ts[0].GetMethod(methodname);
            object[] os = new object[1];
            os[0] = "abc";
            mi.Invoke(o, os);
           
            Console.Read();
        }
    }
}
 
csc /target:exe ConsoleApplication1.cs
阅读(664) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~