51号兵站下载,瓷肌龙儿,龙都网
日期: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
如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复
Blazor server side 自家的一些开源的, 实用型项目的进度之 CEF客户端
.NET IoC模式依赖反转(DIP)、控制反转(Ioc)、依赖注入(DI)
vue+.netcore可支持业务代码扩展的开发框架 VOL.Vue 2.0版本发布
网友评论