加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

vb.net中的lambda表达式

发布时间:2020-12-17 00:08:44 所属栏目:大数据 来源:网络整理
导读:我有些东西让我绝对疯狂…… 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_gro
我有些东西让我绝对疯狂……
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))”出现此错误…

没有为类型’System.Collections.Generic.IList(Of st.data.AccountGroup)’和’System.Collections.Generic.List(Of st.data.AccountGroup)’定义Operator’=’.

但我真的看不出它与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返回一个布尔值),而不是赋值.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读