Can someone explain what the C# “Func” does?

后端 未结 8 2392
情话喂你
情话喂你 2020-12-13 12:34

I\'m reading the Pro MVC 2 book, and there is an example of creating an extension method for the HtmlHelper class.

Here the code example:

public stat         


        
8条回答
  •  天涯浪人
    2020-12-13 13:18

    Because the PageLinks method is an Extension Method.

    In extension method, the first parameter starts with this keyword to indicate that it is an Extension method on the type represented by the first parameter.

    The Func is a delegate which represents a transformation from type T1 to type T2. So basically, your PageLinks method will apply that transformation to int to produce a string.

提交回复
热议问题