zoukankan      html  css  js  c++  java
  • .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 }

    生成解决方案,在ClassLibrary1ClassLibrary1inDebug就可获得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

  • 相关阅读:
    postman一健导入swagger api所有接口
    pycharm 通过project interpreter国内镜像源设置
    Linux常用软件tree,autojump,lrzsz安装
    文献下载好用网站推荐
    SCIP,Clp,Gurobi和Cplex安装
    Linux下SuperLU安装
    【微服务理论】康威定律
    项目实战:动态系统的设计(类似朋友圈)
    认知提升:工作和薪资
    博客园美化 Cnblogs-Theme-SimpleMemory
  • 原文地址:https://www.cnblogs.com/LCCRNblog/p/3682243.html
Copyright © 2011-2022 走看看