Public Class MyList
Inherits List(Of MyObject)
Public ReadOnly Property SelectedCount() As Integer
Get
Return Me.Count(Function(obj) obj.IsSelected)
End Get
End Property
End Class
The above code causes a compile-time error. As you can see, I'm trying to use extension method Count(<predicate>)
. I guess the error is because there is a similarly-named property Count in List
class itself too, hiding the extension member.
My questions here are:
Do I need to explicitly cast my class to something else to access
Count
extension method? If so, exactly which class should it be in the above scenario?Why can't the compiler infer from the usage that I'm referring to a method and not a property?
Does casting involve significant overhead considering that this is a heavily used method (may at times be called hundreds of times a second)?
Is C# any better than VB.NET in this regard?
I'm using .NET 4.0 with VS2010 if that has something to do.
EDIT
Error message:
'
Public ReadOnly Property Count As Integer
' has no parameters and its return type cannot be indexed.