zoukankan      html  css  js  c++  java
  • C# 创建Dll文件供程序调用方法

    C# 创建Dll文件供程序调用方法

        使用C#创建动态Dll文件方法:

      1.  在VS2017环境下,新建-项目-选择类库类型;

      2. 新创建一个.cs文件(如test.cs),编写代码如下:

     1 using System;
     2 using System.Collections.Generic;
     3 using System.Linq;
     4 using System.Text;
     5 using System.Threading.Tasks;
     6 
     7 namespace TestDll
     8 {
     9     public class Test
    10     {
    11         private int a;
    12         private int b;
    13 
    14         public Test(int a,int b )
    15         {
    16             this.a = a;
    17             this.b = b;
    18         }
    19 
    20         public int add()
    21         {
    22             return a + b;
    23         }
    24 
    25         public int add(int x,int y)
    26         {
    27             return x + y;
    28         }
    29 
    30      }
    31 }

          3. 点击项目-右键-重新生成,打开所在文件夹-找到debug文件夹,里面就有TestDll.dll文件

          4. 在程序中调用TestDll.dll文件方法

        a.  在引用中添加TestDll.dll,调用实例为:

    1 using TestDll;
    2  
    3 //实例化对象
    4 Test test = new Test(3, 5);
    5  
    6 //调用方法
    7 MessageBox.Show(test.add().ToString());
    8 MessageBox.Show(test.add(5,5).ToString());

                 

     

     

  • 相关阅读:
    代码对齐[UVA1593]
    数数字
    子序列
    细菌培养
    内联函数那些事情
    一个简单的问题
    头文件重复包含问题的一点笔记
    mapreduce 对文件分词读取
    hadoop hive-2.3.5安装
    hadoop sqoop 实例
  • 原文地址:https://www.cnblogs.com/hbtmwangjin/p/7730418.html
Copyright © 2011-2022 走看看