Why do you need a built-in delegate Func?



  • Decision https://ru.stackoverflow.com/q/479542/194602 Re-established with a built-in delegate Func♪ I can't understand his purpose, how he works and how it works. Maybe someone on some simple example can explain what this is for, how it works and how to use it?



  • Let's say we have a method that draws graphs of different functions for simplicity - algebraic, species y=f(x). Our method is still the same as the function of the species, the main function that matches the intended function, so we can define our method as follows:

     public void DrawFunc(Func<double,double> f)
     {
         for(double x = 0.0; x<1.0; x+=0.001)
         {
             double y = f(x);
             //и далее рисуем точки графика
         }
     }
    

    Now, in order to set the schedule, we need to call our method and give it a proper function. For Func accomplished double, double constituent we will be subject to any function of double FuncName(double ParamName), such as Math.Sin. The challenge will look like:

    DrawFunc(Math.Sin);
    

    This delegate, like his similar Action, is mainly used to fast-track the standard type of delegates. Several individual delegates of the Func visiting T1, identified... ,T16,TResult constituent, and Action T1, ... ,T16, which may be accepted up to 16 (.NET 4+, up to 4 for NET 3.5), the types of which are indicated at the announcement. In addition, for Func, the type of TResult reset must be indicated, and action has always been void. They are no different from the usual delegates.

    https://ru.stackoverflow.com/questions/204937/%D0%92-%D1%87%D0%B5%D0%BC-%D1%80%D0%B0%D0%B7%D0%BD%D0%B8%D1%86%D0%B0-%D0%BC%D0%B5%D0%B6%D0%B4%D1%83-func-%D0%B8-delegate?rq=1 A very similar subject has been discussed and some information is available.


Log in to reply
 


Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2