Func is a generic delegate that encapsulates a method that can accept parameters and return some value
//Annonymous function
Func MyFun1 = delegate(int[] a)
{
string tempString = "";
foreach (int num in a) {
tempString += num.ToString() + ",";
}
return tempString;
};
//Generic or Arrow function
Func MyFun2 = (a) =>
{
string tempString = "";
foreach (float num in a)
{
tempString += num.ToString() + ",";
}
return tempString;
};
private T[] Sort(T[] inputArray)
{
//Sort array
//and return sorted array
return inputArray;
}
int[] numArray = { 10, 15, 26, 98, 68 };
float[] floatArray = { 10.9F, 15.5F, 26, 98.8F, 68 };
lblMessage.Text = "Num : " + MyFun1.Invoke(Sort(numArray));
lblMessage.Text += "Float : " + MyFun2.Invoke(Sort(floatArray));
//Annonymous function
Func
{
string tempString = "";
foreach (int num in a) {
tempString += num.ToString() + ",";
}
return tempString;
};
//Generic or Arrow function
Func
{
string tempString = "";
foreach (float num in a)
{
tempString += num.ToString() + ",";
}
return tempString;
};
private T[] Sort(T[] inputArray)
{
//Sort array
//and return sorted array
return inputArray;
}
int[] numArray = { 10, 15, 26, 98, 68 };
float[] floatArray = { 10.9F, 15.5F, 26, 98.8F, 68 };
lblMessage.Text = "Num : " + MyFun1.Invoke(Sort(numArray));
lblMessage.Text += "Float : " + MyFun2.Invoke(Sort(floatArray));