Step : 2 Edit codes
FuncDelegate.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
/// <summary>
/// Summary description for FuncDelegate
/// </summary>
public delegate string DelegateMethod(string inString);
public delegate int Rountrip();
public class FuncDelegate
{
//
public Func<string, string> FuncMethod = s => s.ToUpper();
public static int n1;
//class constructor
public FuncDelegate() { /* TODO: Add constructor logic here */ }
public int Roundtrip()
{
n1++;
return n1;
}
}
Default.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public delegate void PrintAnonymous(string str);
public partial class _Default : System.Web.UI.Page
{
protected string name = "this is a sentence.";
protected void Page_Load(object sender, EventArgs e)
{
// Instantiate delegate to reference UppercaseString method
FuncDelegate fd = new FuncDelegate();
L1.Text += "<br/>Direct Call fd.FuncMethod(name) writes: " +
fd.FuncMethod(name);
DelegateMethod dm = new DelegateMethod(fd.FuncMethod);
L1.Text += "<br/>dm = new DelegateMethod(fd.FuncMethod) writes: " +
dm(name).ToLower();
L1.Text += "<br/>dm = new DelegateMethod(fd.FuncMethod) writes: " +
dm(name).ToUpper();
//------------------------------------------
PrintAnonymous pa = delegate(string str)
{
L1.Text += "<hr/>Start PrintAnonymous pa" + str;
};
pa(L2.Text = "<br/><font color='Green'>Local
Simple String message : " + name);
pa(L3.Text = "<br/> PrintAnonymous: fd.FuncMethod(name)<br/>" +
fd.FuncMethod(name));
pa(L4.Text = "<br/> PrintAnonymous: dm(name).ToLower() writes: " +
dm(name).ToLower() + "</font>");
}
}
Default.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs"
Inherits="_Default" Debug="true"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>mm.LINQDelegateAnonymous1</title>
</head>
<body bgcolor="#c0c0c0" >
<form id="form1" runat="server"
style="border: 2px solid #800000; background-color: #FFFFCC;
width:600px; padding-left:10px;">
<div style="width: 492px">
<asp:Label ID="L1" runat="server" Text=" "></asp:Label>
<asp:Label ID="L2" runat="server" Text=" "></asp:Label>
<asp:Label ID="L3" runat="server" Text=" "></asp:Label>
<asp:Label ID="L4" runat="server" Text=" "></asp:Label>
<asp:Label ID="L5" runat="server" Text=" "></asp:Label>
</div>
</form>
</body>
</html>