Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Linq Select method with a method as a parameter with two parameters

Tags:

c#

linq

I'm developing a library with .NET Framework 4.5.1 with C#.

I have this code:

user.Groups = modelUser.Groups
    .Select(CreateGroup)
    .ToList();

CreateGroup prototype is:

 public Models.Group CreateGroup(Data.Models.Group modelGroup, bool createMembers)

It has two parameters.

How do I have to modify Select to pass the second parameter, createMembers, to CreateGroup?

like image 414
VansFannel Avatar asked Jan 09 '23 21:01

VansFannel


1 Answers

You are using method group conversion to pass the method CreateGroup as a parameter.

If you use a lambda you can easily use the parameters you want, e.g.

user.Groups = modelUsers.Groups
                        .Select(g => CreateGroup(g, true))
                        .ToList();
like image 192
Dirk Avatar answered Feb 03 '23 13:02

Dirk