作为一个小兵,也有上战场的一天.

 终于要参与到项目中了

 当然,我们常常不可能一个人负责整个项目的开发,往往很多时候是一个人负责一个小的模块


 这里就记录怎么做一个模块的步骤流程,也就是生成一个dll的流程.


1.新建一个类库,在其中定义对象,定义实现功能的函数. 进行封装.

小兵传奇系列:一.参与到项目中,做一个dll_Text

 

 

这里我们定义一个加法的函数

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ClassLibrary1
{
    public class Class1
    {
        public int sumab(int a, int b)
        {

            return a + b;
        
        }

    }
}

 

好了,一个类库就做好了,对其运行build进行封装,就能生成一个dll了

小兵传奇系列:一.参与到项目中,做一个dll_C#_02

 

 

 


2.在新建的Form窗体中调用dll

小兵传奇系列:一.参与到项目中,做一个dll_类的封装_03

小兵传奇系列:一.参与到项目中,做一个dll_类的封装_04

小兵传奇系列:一.参与到项目中,做一个dll_C#_05

 

添加dll的引用

小兵传奇系列:一.参与到项目中,做一个dll_dll的生成_06

小兵传奇系列:一.参与到项目中,做一个dll_Text_07

 

Form代码:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using ClassLibrary1;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            int a = int.Parse(this.textBox1.Text);
            int b = int.Parse(this.textBox2.Text);

            Class1 f = new Class1();//创建一个对象

          int c= f.sumab(a,b);

          this.label1.Text = c.ToString();
        }
    }
}

注意要引用命名空间

using ClassLibrary1;

 把窗体模块设为启动项,运行

小兵传奇系列:一.参与到项目中,做一个dll_Text_08

 

结果:

 

小兵传奇系列:一.参与到项目中,做一个dll_System_09