zoukankan      html  css  js  c++  java
  • C#委托与回调的应用体会(一)

    在实现定积分通用函数计算程序设计过程中,第一次使用C#的委托特性,个人感觉C#的委托有点类似指针,就是把一个方法做成地址传递过去。尽管这种理解不一定严谨,但是取得的效果确实差不多。

    以下便是委托的实际应用~

    namespace functionTheOne
    {
    public partial class Form1 : Form
    {
    private delegate double Function(double x);
    private Function function;
    public Form1()
    {
    InitializeComponent();
    }

    private void label1_Click(object sender, EventArgs e)
    {

    }

    private void button1_Click(object sender, EventArgs e)
    {
    if (radioButton3.Checked == true)
    {
    double a; double b; double z;
    a = Convert.ToDouble(textBox1.Text);
    b = Convert.ToDouble(textBox2.Text);
    function = new Function(jishuan1);
    hanshu(a, b, function);
    }
    if (radioButton2.Checked == true)
    {
    double a; double b; double z;
    a = Convert.ToDouble(textBox1.Text);
    b = Convert.ToDouble(textBox2.Text);
    function = new Function(jishuan2);
    hanshu(a, b, function);
    }
    }

    private void checkBox1_CheckedChanged(object sender, EventArgs e)
    {

    }

    private void label3_Click(object sender, EventArgs e)
    {

    }

    private void Form1_Load(object sender, EventArgs e)
    {

    }

    private void listView1_SelectedIndexChanged(object sender, EventArgs e)
    {

    }

    private void radioButton2_CheckedChanged(object sender, EventArgs e)
    {

    }
    private double hanshu(double a,double b,Function ch)//计算通用的函数
    {
    double sum=0;
    for(int i = 0; i < 10000; i++)
    {
    sum = sum + (a-b)/10000*(ch(((a - b) / 10000 )*i+b)); //a是上限,b是下限
    }
    textBox3.Text = Convert.ToString(sum);
    return sum;
    }
    private double jishuan1(double x )
    {
    return x;
    }
    private double jishuan2(double x)
    {
    return x * x;
    }
    }

    }

  • 相关阅读:
    [转载]美国名校的与机器视觉相关的研发中心网址
    图像匹配方法浅谈
    Debug FFMpeg with CodeBlock
    zircobrowser 源代码学习 一个Android平台的浏览器,适合用在学UI
    iPhone addSubview sameview 是否会产生内存泄漏
    Android 游戏demo
    C# 多线程 注意问题 总结
    Builld with gloox
    论坛专用
    VMware vSphere Client(4.1/5.0/5.1/5.5/6.0) 客户端下载地址
  • 原文地址:https://www.cnblogs.com/fly0512/p/9784328.html
Copyright © 2011-2022 走看看