Skip to content

Commit 44442e5

Browse files
Create delegate for addition and substraction
1 parent 103ed58 commit 44442e5

File tree

1 file changed

+69
-0
lines changed

1 file changed

+69
-0
lines changed
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="practical2b.WebForm1" %>
2+
3+
4+
<!DOCTYPE html>
5+
6+
7+
<html xmlns="http://www.w3.org/1999/xhtml">
8+
<head runat="server">
9+
<title></title>
10+
</head>
11+
<body>
12+
<form id="form1" runat="server">
13+
<div>
14+
<asp:Label ID="Label1" runat="server" BorderStyle="Groove" Text="Delegate Demo"></asp:Label>
15+
<br />
16+
<br />
17+
<asp:Label ID="Label2" runat="server" Text="Enter the Number 1:"></asp:Label> &nbsp;
18+
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
19+
20+
<br />
21+
<br />
22+
<asp:Label ID="Label3" runat="server" Text="Enter the Number 2:"></asp:Label> &nbsp;&nbsp;
23+
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
24+
<br />
25+
<br />
26+
<br />
27+
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Delegate Demo" />
28+
<br />
29+
<br />
30+
<asp:Label ID="Label4" runat="server" Text="Label"></asp:Label>
31+
<br />
32+
<br />
33+
<asp:Label ID="Label5" runat="server" Text="Label"></asp:Label>
34+
</div>
35+
</form>
36+
</body>
37+
</html>
38+
39+
40+
Pract2b.aspx.cs
41+
using System;
42+
using System.Collections.Generic; using System.Linq;
43+
using System.Reflection.Emit; using System.Web;
44+
using System.Web.UI;
45+
using System.Web.UI.WebControls;
46+
47+
48+
namespace practical2b
49+
{
50+
public delegate int MathOperation(int a, int b);
51+
public partial class WebForm1 : System.Web.UI.Page
52+
53+
{
54+
int Add(int a, int b)
55+
{
56+
return a + b;
57+
}
58+
int Subtract(int a, int b)
59+
{
60+
return a - b;
61+
}
62+
protected void Button1_Click(object sender, EventArgs e)
63+
{
64+
int x = Convert.ToInt32(TextBox1.Text); int y = Convert.ToInt32(TextBox2.Text);
65+
MathOperation add = new MathOperation(Add); MathOperation subtract = new MathOperation(Subtract); Label4.Text = add(x, y).ToString();
66+
Label5.Text = subtract(x, y).ToString();
67+
}
68+
}
69+
}

0 commit comments

Comments
 (0)