Using System;
Using System. Collections. Generic;
Using System. LINQ;
Using System. text;
NamespaceFuncdemo
{
ClassProgram
{
Static VoidMain (String[] ARGs)
{
//Similar delegation Function
Func<String,Int>Test=Tsetmothod;
Console. writeline (test ("123"));
Func<String,Int>Test1=Tsetmothod;
//You only need to call this class to reduce repeatedCode
Callmethod<String>(Test1,"123");
//Or use this
Callmethod<String>(NewFunc<String,Int>(Tsetmothod ),"123");
Callmethod (NewFunc<String,Int>(Tsetmothod ),"123");
}
Public static int tsetmothod ( string name)
{< br> If ( string . isnullorempty (name ))
{< br> return 1 ;
}< br> return 0 ;
}
//The following code is often used for transformation.
// Try
// {
/// /Do (); only this method changes
// }
// Catch (system. Exception ex)
// {
// // Log (E );
// }
// Finally
// {
/// /Doother ();
// }
//
Public Static Void Callmethod < T > (Func < T, Int > Func, t item)
{
Try
{
Int I = Func (item );
Console. writeline (I );
}
Catch (Exception E)
{
}
Finally
{
}
}
}
}
Func example