我如何从过程调用中删除参数或参数

时间:2015-12-09 21:10:21

标签: asp.net vb.net

当我运行我的代码时,我收到一条通知

  

public readonly属性Count as integer没有参数和它   返回类型无法编入索引。

我该如何解决这个问题?

Public Sub Connect(userName As String)
    Dim id = Context.ConnectionId


    If ConnectedUsers.Count(Function(x) x.ConnectionId = id) = 0 Then
        ConnectedUsers.Add(New UserDetail() With { _
            Key .ConnectionId = id, _
            Key .UserName = userName _
        })

        ' send to caller
        Clients.Caller.onConnected(id, userName, ConnectedUsers, CurrentMessage)

        ' send to all except caller client

        Clients.AllExcept(id).onNewUserConnected(id, userName)
    End If

End Sub

1 个答案:

答案 0 :(得分:0)

Change your If statement as suggested by Plutonix. But he was not giving you the full code:

If ConnectedUsers.Where(Function(x) x.ConnectionId = id).Count() = 0 Then

When you access Count on the List type, it's only a property, not a method. The Where extension method allows you to pass in the lambda check, and returns you a different object that has a Count method (not property) like the one you were expecting to see.