-
C#教程之C#教程之C# DLL(程序集)的生成和调用
本站最新发布 C#从入门到精通
试听地址 https://www.xin3721.com/eschool/CSharpxin3721/
试听地址 https://www.xin3721.com/eschool/CSharpxin3721/
日期:2018年11月24日
环境:Window 10,VS2015
一、利用VS2015自带的工具生成DLL
步骤:
1.利用C#准备一个.cs文件;
1 using System; 2 3 public class MyMath 4 { 5 public MyMath() 6 { 7 Console.WriteLine("This is DLL!!!"); 8 } 9 public long Add(long a,long b) 10 { 11 return (a + b); 12 } 13 }
2.开始菜单->Visual Studio 2015->VS2015 开发人员命令提示;
3.输入csc /t:library /out:C:\Users\xxxxx\Desktop\study\AcmeCollections\AcmeCollections\MyMath.dll C:\Users\xxxxx\Desktop\study\AcmeCollections\AcmeCollections\MyMath.cs;
注解:
1)library:意思是编译成类库,否则必须有Main();
2)/out:C:\Users\xxxxx\Desktop\study\AcmeCollections\AcmeCollections\MyMath.dll:输出文件的位置和名称;
3)C:\Users\xxxxx\Desktop\study\AcmeCollections\AcmeCollections\MyMath.cs:源文件的位置和名称;
上图没有出现报错,即操作成功;
二、给你的项目添加引用此DLL,并运行;
1 using System; 2 using System.Collections.Generic; 3 using System.Linq; 4 using System.Text; 5 using System.Threading.Tasks; 6 using System.Runtime.InteropServices; 7 8 namespace AcmeCollections 9 { 10 class Program 11 { 12 static void Main(string[] args) 13 { 14 long ans; 15 string str; 16 MyMath myMath = new MyMath(); 17 ans = myMath.Add(1, 2); 18 str = Convert.ToString(ans); 19 Console.WriteLine(str); 20 Console.ReadLine(); 21 } 22 } 23 }
运行结果:
三、参考链接
1.https://www.cnblogs.com/zuoguanglin/archive/2012/02/23/2364613.html
2.https://docs.microsoft.com/zh-cn/dotnet/csharp/tour-of-csharp/program-structure
栏目列表
最新更新
如何使用OS模块中的stat方法
Python os 模块
seek() 方法
python打开文件实例1
Python写入文件
什么是流?
文件操作如何进制逐行读取
Python相对路径
with创建临时运行环境
Python文件操作
.Net Standard(.Net Core)实现获取配置信息
Linux PXE + Kickstart 自动装机
Shell 编程 基础
Shell 编程 条件语句
CentOS8-网卡配置及详解
Linux中LVM逻辑卷管理
1.数码相框-相框框架分析(1)
Ubuntu armhf 版本国内源
Linux中raid磁盘阵列
搭建简易网站
access教程之Access简介
mysql 安装了最新版本8.x版本后的报错:
Mysql空间数据&空间索引(spatial)
如何远程连接SQL Server数据库的图文教程
复制SqlServer数据库的方法
搜索sql语句
sql中返回参数的值
sql中生成查询的模糊匹配字符串
数据定义功能
数据操作功能