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#
Developer technologies | C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
{count} votes

2 answers

Sort by: Most helpful
  1. Castorix31 91,276 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,591 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' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.