gpt4 book ai didi

vb.net - vb.net 中的 lambda 表达式

转载 作者:行者123 更新时间:2023-12-04 16:38:02 25 4
gpt4 key购买 nike

我有一些事情让我非常疯狂......

    Public Function GetAccountGroups() As IList(Of AccountGroup)
Dim raw_account_groups As IList(Of AccountGroup)
raw_account_groups = _repository.GetAccountGroups().ToList()
Dim parents = (From ag In raw_account_groups _
Where ag.parent_id = 0 _
Select ag).ToList()

parents(0).sub_account_groups = (From sag In raw_account_groups _
Where sag.parent_id = 0 _
Select sag).ToList()

Dim sql_func As Func(Of AccountGroup, List(Of AccountGroup)) = Function(p) _
(From sag In raw_account_groups _
Where sag.parent_id = p.id _
Select sag).ToList()

parents.ForEach(Function(p) p.sub_account_groups = sql_func(p))

Return parents
End Function

线路 parents.ForEach(Function(p) p.sub_account_groups = sql_func(p))有这个错误...

Operator '=' is not defined for types 'System.Collections.Generic.IList(Of st.data.AccountGroup)' and 'System.Collections.Generic.List(Of st.data.AccountGroup)'.



但我真的看不出它与 Rob Connery 的这段代码有何不同
public IList<Category> GetCategories() {
IList<Category> rawCategories = _repository.GetCategories().ToList();
var parents = (from c in rawCategories
where c.ParentID == 0
select c).ToList();
parents.ForEach(p =>
{
p.SubCategories = (from subs in rawCategories
where subs.ParentID == p.ID
select subs).ToList();
});

return parents;
}

哪个编译完美......我做错了什么?

最佳答案

VB.Net 中的 Lambda 必须返回一个值,因此您的等号 ('=') 被解释为比较(以便 lambda 返回一个 bool 值),而不是赋值。

关于vb.net - vb.net 中的 lambda 表达式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67916/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com