Step: 2 Edit code
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()
{
//
// TODO: Add constructor logic here
//
}
public string StringProcessor(string title)
{
Func<string, int, string[]> funcRefofAMethod = UsingFunc;
//string title = "The Scarlet Letter";
// Use delegate instance to call ExtractWords method and display
result
foreach (string word in UsingFunc(title, 5))
{
str+=(word) + " " ;
}
foreach (string word in funcRefofAMethod(title, 5))
{
str += (word) + " ";
}
return str;
}
public static string[] UsingFunc(String param, int limit)
{
char[] delimiters = new char[] { ' ' };
string[] str;
if (limit > 0)
{
str= param.Split(delimiters, limit);
}
else
{
str = param.Split(delimiters);
}
return str;
}
}
Defualt.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/>Dear Horatio You Knew Hamlet");
something();
}
protected void something()
{
L1.Text += "<br/>----- Calling a Proteced method";
Func<string, int, string[]> funcLocalMethod = UsingCharArray;
string title = "<br/> The Crown Prince of Denmark";
// Use foreach to display result
foreach (string word in funcLocalMethod(title, 5))
{
L1.Text+=(word) + " ";
}
}
protected string[] UsingCharArray(string param, int stringLength)
{
char[] spacers = new char[] { ' ' };
this.str = param.Length.ToString();
L1.Text += " & is : " + str + " Chracter long" ;
if (stringLength > 0)
{
return param.Split(spacers, stringLength);
}
else
{
return param.Split(spacers);
}
}
}