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

vb.net – vb计数奇怪的行为

发布时间:2020-12-17 00:32:53 所属栏目:大数据 来源:网络整理
导读:尝试将Count用作lambda时,我遇到了一个奇怪的错误 ‘Public ReadOnly Property Count As Integer’ Has no parameters and its return type cannot be indexed’ 如果我算上LongCount,它就会神奇地起作用.根据this blog post 3年前,这是一个众所周知的问题.
尝试将Count用作lambda时,我遇到了一个奇怪的错误

‘Public ReadOnly Property Count As Integer’ Has no parameters and its
return type cannot be indexed’

如果我算上LongCount,它就会神奇地起作用.根据this blog post 3年前,这是一个众所周知的问题.它似乎仍然存在.我的问题是如何解决这个问题?

Module Module1
    Sub Main()

        Dim wit2 As New List(Of TestCount) From {New TestCount With {.title = "foo" _,.PartNumber = "bar"} _,New TestCount With {.title = "chuck" _,.PartNumber = "norris"}}                                          
        Console.WriteLine(wit2.Count(Function(x) x.title = "chuck"))
    End Sub
    Friend Class TestCount
        Property title As String
        Property PartNumber As String
    End Class
End Module
试试这个
wit2.Where(Function(elem) elem.title="chuck").Count()

它比上面的要简单得多.

希望它会有所帮助

List具有List类中定义的Count属性和IEnumerable上定义的Count()扩展方法.这似乎是多余的,但请记住,并非所有IEnumerable实现都定义了计数.

由于任何实现ICollection或ICollection的集合都必须指定Count属性.由于List,数组和许多其他集合实现ICollection,这意味着直接调用Count并避免调用扩展方法.

(编辑:李大同)

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

    推荐文章
      热点阅读