未找到类型'String()'上的公共成员'Count'。 [英] Public member 'Count' on type 'String()' not found.

查看:269
本文介绍了未找到类型'String()'上的公共成员'Count'。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在下面显示的代码上收到上述错误消息。代码在公共函数中,我在页面上有正确的import语句(Imports System.Linq)。无论我做什么,我都无法在没有错误消息的情况下通过这段代码。任何建议都将不胜感激。



 如果 sBreadcrumb.Split(  )。计数>  1  然后 
root = CInt (sBreadcrumb.Split( )( 1 ))
oPage = SiteManagerPage( CInt (root), Nothing
结束 如果

解决方案

尝试如果是sBreadcrumb.Split(。)。长度> 1然后


数组类型不支持计数属性。

集合,列表,... 类型支持计数物业。



使用长度属性而不是计数 about 数组类型。


你错过了()

如果sBreadcrumb.Split( )。< u> Count() >   1 然后
root = CInt(sBreadcrumb) .Split( )( 1 ))
oPage =新SiteManagerPage(CInt(root),Nothing)
结束如果





请注意 Count()扩展方法可以与 IEnumerable 一起使用,但Collection类型有 Count 属性和数组类型有长度属性。 大多数集合都有一个更有效的长度或计数属性



何时使用Count()。这种扩展方法确实有一些很好的用途。如果你使用LINQ查询表达式,或者由于其他原因有一个IEnumerable实例,那么它是确定存在多少元素的最佳方法。



Count方法可以与Func类型的参数一起使用。例如:

 Dim greaterThanTwo As Integer = array.Count(Function(element)element >   2 


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.

If sBreadcrumb.Split(".").Count > 1 Then
 root = CInt(sBreadcrumb.Split(".")(1))
 oPage = New SiteManagerPage(CInt(root), Nothing)
End If

解决方案

Try If sBreadcrumb.Split(".").Length > 1 Then


Array Type does not support Count Property.
Only Collection, List, ... Type does support Count Property.

Use Length property instead Count about Array Types.


You missed (),

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.:

Dim greaterThanTwo As Integer = array.Count(Function(element) element > 2)


这篇关于未找到类型'String()'上的公共成员'Count'。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆