一 设计界面

二 编写代码
1 委托的第一种方法(声明 实例化 使用 )
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;
namespace 计算
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
public delegate int Calculate(int x, int y); //声明委托——1
int Add(int x, int y) { return x + y; }//加、减、乘、除的方法——2
int Minus(int x, int y) { return x - y; }
int Multiply(int x, int y) { return x * y; }
int Divide(int x, int y) { return x / y; }
private void button1_Click(object sender, EventArgs e)
{
Calculate a = new Calculate(Ad

这篇博客详细介绍了如何在C#窗体程序中利用委托进行加减乘除计算的三种方法。首先,通过声明、实例化和使用委托实现计算;其次,运用匿名方法和Lambda表达式简化代码;最后,展示了通过事件处理方式组合多个计算操作。每种方法都配合具体代码进行了说明,并在运行中得到了预期结果。
&spm=1001.2101.3001.5002&articleId=89309450&d=1&t=3&u=43fbf7f2a5574d4eac253cae36f665c6)
1360

被折叠的 条评论
为什么被折叠?



