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

后端 未结 8 2395
情话喂你
情话喂你 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:31

    Func means a callback method that takes an int parameter and returns a String as the result.

    The following expression, which is known as a lambda expression:

    Func pageUrl = i => "Page" + i;
    

    expands to something like this:

    Func pageUrl = delegate(int i)
    {
        return "Page" + i;
    }
    

提交回复
热议问题