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