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

  • 相关阅读:
    《英文论文写作再也不难了(工具篇),不收藏就找不到了》
    teachable-machine:探索机器学习如何工作,浏览器中实时浏览
    rasa_core:基于机器学习的对话引擎
    DeepMoji:机器学习模型分析情绪, 情感
    TensorFlow LSTM 注意力机制图解
    Fabrik – 在浏览器中协作构建,可视化,设计神经网络
    移动深度学习 Mobile-deep-learning(MDL)
    Serpent.AI
    face-alignment:用 pytorch 实现的 2D 和 3D 人脸对齐库
    ZhuSuan 是建立在Tensorflow上的贝叶斯深层学习的 python 库
  • 原文地址:https://www.cnblogs.com/LCCRNblog/p/3682243.html
Copyright © 2011-2022 走看看