I am getting a wierd error when trying to use Count as a lambda
'Public ReadOnly Property Count As Integer' Has no parameters and its return type cannot be indexed'
If i Count to LongCount it magically works. According to this blog post 3 years ago this was a known issue. It seems it still is. My question is how do i resolve this issue?
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
try this
wit2.Where(Function(elem) elem.title="chuck").Count()
It is much simpler than above one.
hope it will help
List has both the Count property defined in the List class, and the Count() extension method defined on IEnumerable. This may seem redundant, but keep in mind that not all IEnumerable implementations have a count defined.
As any collection that implements ICollection or ICollection must specify a Count property. Since List, arrays, and many other collections implement ICollection, this means call Count directly and avoid calling the extension method.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With