c# - Linq Select 方法,一个方法作为一个参数,有两个参数

标签 c# linq

我正在使用 .NET Framework 4.5.1 和 C# 开发一个库。

我有这个代码:

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

CreateGroup原型(prototype)为:

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

它有两个参数。

我必须如何修改 Select 以将第二个参数 createMembers 传递给 CreateGroup

最佳答案

您正在使用方法组转换将方法 CreateGroup 作为参数传递。

如果您使用 lambda,您可以轻松地使用您想要的参数,例如

user.Groups = modelUsers.Groups
                        .Select(g => CreateGroup(g, true))
                        .ToList();

关于c# - Linq Select 方法,一个方法作为一个参数,有两个参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25699160/

相关文章:

c# - 在子查询中涉及计数的高效查询

c# - C#发送邮件时如何实现Sender ID?

c# - Linq 查询 - 多个连接到一个表

c# - 使用泛型的 LINQ 连接

.net - LINQ 到 SQL : How to check if any item in one entity collection exists in another entity collection?

c# - 我该如何解释这段代码?

c# - 生成具有指定最后一位的大质数

c# - 错误 CS0246 : The type or namespace name 'StreamingContext' could not be found (are you missing a using directive or an assembly reference?)

c# - 为什么类型对象中的 1 不能转换为 double

c# - 如何将 ImageBox.Image 转换为 Image<Bgr, Byte>