usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;namespacefuncdemo{classProgram {Static voidMain (string[] args) { //similar delegate functionsfunc<string,int> test =Tsetmothod; Console.WriteLine (Test ("123")); Func<string,int> test1 =Tsetmothod; //just call this class to reduce the duplication of codecallmethod<string> (Test1,"123"); //or Use thiscallmethod<string> (Newfunc<string,int> (Tsetmothod),"123"); Callmethod (Newfunc<string,int> (Tsetmothod),"123"); } Public Static intTsetmothod (stringname) { if(string. IsNullOrEmpty (name)) {return 1; } return 0; } //retrofits often appear under similar code//Try//{ ////do (); This is the only way to change //} //catch (System.Exception ex)//{ // //Log (e);//} //finally//{ ////doother (); //} // Public Static voidCallmethod<t> (Func<t,int>func,t Item) { Try { intI=func (item); Console.WriteLine (i); } Catch(Exception e) {}finally{}}}}func example
C # FUNC Application