Beginner Delegate program

Add Two Number Delegate Program

public delegate int AddTwoNumberDel(int fvalue, int svalue);

private void btnClick_Click(object sender, EventArgs e)
{
AddTwoNumberDel AT = Addnumber; // create delegate instance
//is shorthand for
//AddTwoNumberDel AT = new AddTwoNumberDel(Addnumber);
int a = Convert.ToInt16(txtfvalue.Text);
int b = Convert.ToInt16(txtsvalue.Text);
txtresult.Text = AT(a, b).ToString(); // invoke Method
//is shorthand for
//txtresult.Text = AT.Invoke(a, b).ToString();
}

public int Addnumber(int fvalue, int svalue)
{
return fvalue + svalue;
}

Note:

Copy and past your VS Editor it will Work... Do you want sample application mail me ...

0 Comments

Featured Post

Improving C# Performance by Using AsSpan and Avoiding Substring

During development and everyday use, Substring is often the go-to choice for string manipulation. However, there are cases where Substring c...

MSDEVBUILD - English Channel

MSDEVBUILD - Tamil Channel

Popular Posts