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

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

    The Func line that you are inquiring about is known as a lambda expression.

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

    This line can be described as a function that takes an int parameter (i) and returns a string "Page" + i;

    It can be re-written as:

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

提交回复
热议问题