C#中创建并引用dll 工具为vs2008

将vs2008 的配置改为适合C#的配置

tools -> Import and Export Settings  -> Reset All Settings   选择C#开发配置

新建一个类库,名字为mydll



using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace mydll
{
    public class Class1
    {
        public static int Mysum(int a,int b)
        {
            return a + b;
        }
    }
    public class Class2
    {
        public static int MyMax(int a, int b)
        {
            return (a > b ? a : b);
        }
    }
}

使用合适的解决方案平台,解决方案配置为Release。例如我的是Release    x64
只需生成解决方案就好,不用启动调试(小三角),生成 mydll.dll


调用 mydll.dll
1、新建一个控制台项目 usedll
2、将生成的 mydll.dll  拷贝到新建的项目中
3、 在解决方案浏览器(Solution Explorer)中右击引用(references),右键添加引用(Add Reference),将刚才的mydll.dll添加进去。
4、在代码中添加 using mydll;

代码:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using mydll;
namespace usedll
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine(Class1.Mysum(3,4));
            Console.ReadKey();
        }
    }
}

这样就ok了





  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值