.NET在VS2008中生成DLL并调用

1.生成DLL

打开VS2008 - >新建->项目->类库->ClassLibrary1,在ClassLibrary1中会自动创建一个Class1类

class1中加入代码如下:

 1 using System;
 2 using System.Collections.Generic;
 3 using System.Linq;
 4 using System.Text;
 5 namespace ClassLibrary1
 6 {
 7     public class Class1
 8     {
 9         private int a = 0;
10         private int b = 0;
11         public int SetA
12         {
13             get { return a; }
14             set { a = value; }
15         }
16 
17         public int SetB
18         {
19             get { return b; }
20             set { b = value; }
21         }
22         public int getResult()
23         {
24             return a - b;
25         }
26     }
27 }

创建两个子类:

 1 //子类ClassAdd
 2 using System;
 3 using System.Collections.Generic;
 4 using System.Linq;
 5 using System.Text;
 6 namespace ClassLibrary1
 7 {
 8     public class ClassAdd : Class1
 9     {
10         public int getResult()
11         {
12             return SetA + SetB;
13         }
14     }
15 }
 1 //子类ClassMult
 2 using System;
 3 using System.Collections.Generic;
 4 using System.Linq;
 5 using System.Text;
 6 namespace ClassLibrary1
 7 {
 8     public class ClassMult : Class1
 9     {
10         public int getResult()
11         {
12             return SetA * SetB;
13         }
14     }
15 }

生成解决方案,在ClassLibrary1\ClassLibrary1\bin\Debug就可获得DLL文件

2.调用DLL

VS2008 - >新建->网站 创建一个websit1(asp.net网站)

在该项目下生成一个文件夹,命名bin:右键->新建文件夹->bin

然后在该文件件中引入之前生成的dll:bin右键->添加引用->浏览->找到ClassLibrary1.dll

在Default.aspx.cs添加如下代码:

 1 using System;
 2 using System.Configuration;
 3 using System.Data;
 4 using System.Linq;
 5 using System.Web;
 6 using System.Web.Security;
 7 using System.Web.UI;
 8 using System.Web.UI.HtmlControls;
 9 using System.Web.UI.WebControls;
10 using System.Web.UI.WebControls.WebParts;
11 using System.Xml.Linq;
12 using ClassLibrary1;
13 public partial class _Default : System.Web.UI.Page 
14 {
15     protected void Page_Load(object sender, EventArgs e)
16     {
17         ClassAdd add = new ClassAdd();
18         ClassMult mult = new ClassMult();
19         add.SetA = 10;
20         add.SetB = 11;
21         Response.Write(add.getResult().ToString());
22         mult.SetA = 10;
23         mult.SetB = 11;
24         Response.Write("<br />" + mult.getResult().ToString());
25     }
26  
27 }

3.运行website1

 网页显示结果:

21
110

 

转载于:https://www.cnblogs.com/LCCRNblog/p/3682243.html

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值