Click here to Skip to main content
16,004,452 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am getting the above error message on the code shown below. The code is in a public function and I do have correct import statement on the page (Imports System.Linq). No matter what I do I can't get past this bit of code without the error message. Any suggestions would be greatly appreciated.

VB
If sBreadcrumb.Split(".").Count > 1 Then
 root = CInt(sBreadcrumb.Split(".")(1))
 oPage = New SiteManagerPage(CInt(root), Nothing)
End If
Posted
Updated 23-May-14 18:08pm
v2
Comments
Member 4627922 3-Jul-21 2:38am    
But why does this code work?:

Dim strings As String() = {"A", "B"}
Console.WriteLine(strings.Count.ToString)

Try If sBreadcrumb.Split(".").Length > 1 Then
 
Share this answer
 
Array Type does not support Count Property.
Only Collection, List, ... Type does support Count Property.

Use Length property instead Count about Array Types.
 
Share this answer
 
You missed (),
C#
If sBreadcrumb.Split(".").Count() > 1 Then
  root = CInt(sBreadcrumb.Split(".")(1))
  oPage = New SiteManagerPage(CInt(root), Nothing)
 End If


Note that Count() extension method can be used with IEnumerable but Collection types there is Count property and for array types there is Length property. Most collections have a Length or Count property that is more efficient.

When to use Count(). This extension method does have some good uses. If you use a LINQ query expression, or for some other reason have an IEnumerable instance, it is the best way to determine how many elements are present.

The Count method can be used with an argument of type Func. e.g.:
C#
Dim greaterThanTwo As Integer = array.Count(Function(element) element > 2)
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900