Vb count Strange behavior

I get a weird error when trying to use Count as a lambda

'Public ReadOnly Count As Integer Property' 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 he is still there. My question is: how to solve this problem?

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 
+6
source share
1 answer

try it

 wit2.Where(Function(elem) elem.title="chuck").Count() 

It is much simpler than the above.

hope this helps

The list has the Count property, defined in the List class, and the Count () extension method, defined in IEnumerable. This may seem redundant, but keep in mind that not all IEnumerable versions have a specific score.

Like any collection that implements ICollection or ICollection, the Count property must be specified. Since List, arrays, and many other collections implement ICollection, this means that calling Count directly does not call the extension method.

+7
source

All Articles