Step: 2 Edit Codes
Class: FuncGeneric.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
//for IEnumerator and GetEnumerator();
using System.Collections;
/// <summary>
/// Summary description for FuncGeneric
/// </summary>
public class FuncGeneric
{
public string strProcess; public string str;
public FuncGeneric(){ str += "<br/>Constructor started"; }
public string StringProcessor(string title)
{
char [] spacer = new char[]{' '};
str += "<br/> Func<(Of <(T1, T2, TResult>)>)<font color='Teal'>";
str+="delegate with anonymous methods </font>";
// delegating a routine
Func<string, string[]> funcRefofAMethod = delegate(string s)
{
int i = s.Length;
char[] spacers = new char[] { ' ' };
return i > 0 ? s.Split(spacers, i) : s.Split(spacers);
};
str += "<br/>----->";
foreach (string word in funcRefofAMethod(title))
{
str += (word) + "  / ";
}
//alternate way
Func<string,string[]> usingLamda = (s) =>
s.Split(spacer);
//
str += "<br/> Using Lamda Expression <font color='red'>";
str+="(s) => s.Split(spacer);</font>";
str += "<br/>----->";
foreach(string word in usingLamda(title))
{
str += (word) + "  / ";
}
return str;
}
public static string[] UsingFunc(String param, int limit)
{
char[] spacers = new char[] { ' ' };
string[] str;
if (limit > 0)
{
str= param.Split(spacers, limit);
}
else
{
str = param.Split(spacers);
}
return str;
}
}
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 partial class _Default : System.Web.UI.Page
{
protected string str;
protected void Page_Load(object sender, EventArgs e)
{
FuncGeneric fg = new FuncGeneric();
L1.Text += "----- Calling a Method in an external Class";
L1.Text += fg.StringProcessor("<br/>If it be love indeed, tell me
how much");
}
}
Default.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs"
Inherits="_Default" %>
<!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.LINQFuncDelegate2: Func Delegate and Lamda </title>
</head>
<body bgcolor="#cccccc">
<form id="form1" runat="server"
style="background-color: #FFFFCC; border: thick solid #800080;
padding: 10px; margin: 10px; width: 500px">
<div>
<asp:Label ID="L1" runat="server" Text=""></asp:Label>
</div>
</form>
</body>
</html>