What problem does Func solve?

Mr Edge 221 Reputation points
2021-07-23T11:37:11.07+00:00

I'm struggling to understand when and why I would use Func and what problem does it resolve?

I've read MSDN, tutorials teacher etc etc but all have examples but not necessarily explaining what problem it could resolve or when I could/should use it?

Could anyone give a very simple example(s) to demo this please?

Developer technologies C#
{count} votes

2 answers

Sort by: Most helpful
  1. Castorix31 90,521 Reputation points
    2021-07-23T12:04:55.567+00:00

    You can see this article for example : How and Why to Use Delegates in C#

    0 comments No comments

  2. Karen Payne MVP 35,586 Reputation points Volunteer Moderator
    2021-07-23T16:08:05.513+00:00

    Another usage for projections.

    Let's say you want to return a custom list as shown here from this model/class, we define a class as follows and shown below.

    Func receives a Customer and returns a CustomerEntity. If this as a ASP.NET we would use mapping such as auto-mapper instead for CRUD, here it's in a desktop app working with Entity Framework Core.

    117527-figure1.png

    Also, when using LINQ/Lambda, Select, Where they use Func also as a predicate. Hover over a Select to see it. Also, read the docs and search for Func here

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.