How does Func Work?

后端 未结 3 1148
悲哀的现实
悲哀的现实 2021-02-05 08:58

I am creating a Distinct extension method where I can pass in the criteria like the following.

persons.Distinct(p => p.Name); 

I got the co

3条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-02-05 09:13

    Func
    

    defines a function that accepts one parameter (of type T) and returns an object (of type TResult).

    In your case, if you want a function that takes a Person object and returns a string...you'd want

    Func
    

    which is the equivalent of:

    string Function(Person p)
    {
        return p.Name;
    }
    

提交回复
热议问题