您的位置:首页 > 编程语言 > C#

c# 调用 .cs 生成的 dll 文件

2013-08-29 16:41 253 查看
第一步:

打开VS2010(我用的是这个版本的)

文件->新建->项目->类库->

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

namespace add_dll
{
public class Class1
{
public static int add(int a, int b)
{
return a + b;
}
}
}


上面为简单范例

生成后debug 或者release 里面会生成dll文件

第二步:

新建C#控制台程序(当然也可以是其他)

在解决方案的地方引用 刚刚生成的dll文件;

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
using add_dll;
namespace test_dll_
{
class Program
{

static void Main(string[] args)
{
int a = Class1.add(5,10);
}
}
}


即可调用dll里面的函数。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: