Step: 1 Create new site ( http://manas6/aspnet.35/mm.FuncGeneric1/ )

Add a class

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) + "&nbsp" ;
}
foreach (string word in funcRefofAMethod(title, 5))
{

str += (word) + "&nbsp";
}

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) + "&nbsp";
}

}
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);
}
}


}
 

Step: 3 Runtime analysis. Note in for each loop I used with of the references, "UsingFunc" mehod or "funcRefofAMethod" respectively, the results were same.

Now set two break points, and use F10 to check how both the arguments are processed by Func entity (a Generic Delegate )  in c#.