Code:
1 usingSystem;2 usingSystem.Collections.Generic;3 usingSystem.Linq;4 usingSystem.Text;5 usingSystem.Threading.Tasks;6 7 namespaceDelegate _ Example8 {9 Static class ProgramTen { One //defining a delegate (double type) A Delegate DoubleIntegand (Doublex); - - //Defining Methods the Static DoubleMETHOD1 (Doublex) - { - return 2* x +1; - } + - Static DoubleMETHOD2 (Doublex) + { A returnX *x; at } - - //definition is a method of delegating - Static DoubleDefiniteintegrate (Integand F,DoubleADoubleb) - { - Const intSect = +; in - DoubleArea =0; to + DoubleDelta = (B-A)/sect; - the for(inti =0; I < sect; i++) * { $ //The f here represents Method1 or METHOD2. Panax Notoginseng //pass them a value of type double that returns a value of type double. - //the double value at this point is long multiplied by the width "A + i * delta" theArea + = Delta * F (A + I *delta); + } A the returnArea ; + } - $ Static voidMain (string[] args) $ { - //Calling Methods - //Pass in a method theConsole.WriteLine (Program.definiteintegrate (METHOD1,1,5)); - Console.WriteLine ();WuyiConsole.WriteLine (Program.definiteintegrate (METHOD2,0,1)); the - Console.readkey (); Wu } - } About } $
C #-A general method for determining integral of trust