文章目录
- 1.VS2019创建C#主程序
- 2.编译主程序
- 3.添加类库工程,并添加计算逻辑
- 4.给主程序添加引用项
- 5.重新编译主程序
- 6.主程序添加测试逻辑
1.VS2019创建C#主程序
2.编译主程序
debug目录下生成exe:
3.添加类库工程,并添加计算逻辑
添加计算逻辑:
namespace Calculate
{
public class CalculateAssistant
{
// +
public double Sum(double a, double b)
{
return a + b;
}
public Int64 Sum(Int64 a, Int64 b)
{
return a + b;
}
// -
public double Sub(double a, double b)
{
return a - b;
}
public Int64 Sub(Int64 a, Int64 b)
{
return a - b;
}
// *
public double Multiple(double a, double b)
{
return a * b;
}
public Int64 Multiple(Int64 a, Int64 b)
{
return a * b;
}
// /
public double Divide(double a, double b)
{
return a / b;
}
public Int64 Divide(Int64 a, Int64 b)
{
return a / b;
}
}
}
4.给主程序添加引用项
5.重新编译主程序
先生成依赖项目,再生成主程序:
debug目录增加了dll文件:
6.主程序添加测试逻辑
using Calculate;
namespace Main
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Add_Click(object sender, EventArgs e)
{
Calculate.CalculateAssistant calc = new CalculateAssistant();
double result = calc.Sum(double.Parse(textBox1.Text),double.Parse(textBox2.Text));
textBox3.Text = result.ToString();
}
private void Sub_Click(object sender, EventArgs e)
{
Calculate.CalculateAssistant calc = new CalculateAssistant();
double result = calc.Sub(double.Parse(textBox1.Text), double.Parse(textBox2.Text));
textBox3.Text = result.ToString();
}
private void Multi_Click(object sender, EventArgs e)
{
Calculate.CalculateAssistant calc = new CalculateAssistant();
double result = calc.Multiple(double.Parse(textBox1.Text), double.Parse(textBox2.Text));
textBox3.Text = result.ToString();
}
private void Divide_Click(object sender, EventArgs e)
{
Calculate.CalculateAssistant calc = new CalculateAssistant();
double result = calc.Divide(double.Parse(textBox1.Text), double.Parse(textBox2.Text));
textBox3.Text = result.ToString();
}
}
}