Question

I would you convert this from C# code in vb.net

static List<UserDetail> ConnectedUsers = new List<UserDetail>();

if (ConnectedUsers.Count(x => x.ConnectionId == id) == 0){
    //do somthing 
}

I tried to convert with the website

http://www.developerfusion.com/tools/convert/csharp-to-vb/

and I've got this code,

If ConnectedUsers.Count(Function(x) x.ConnectionId = id) = 0 Then
    'do something
end if

but doesnt work visual studio tells me (error on this part 'ConnectedUsers.Count') "'Public ReadOnly property count as integer' Has no parameters and its return value cannot be indexed. "

Thank you in advance for your help

Edit 1 I put it the declaration

Shared ConnectedUsers As New List(Of UserDetail)()

and in another class in the same namespace I have got this

Imports System.Collections.Generic
Imports System.Linq
Imports System.Web

Namespace SignalRChat.Common
    Public Class UserDetail
        Public Property ConnectionId() As String
            Get
                Return m_ConnectionId
            End Get
            Set(value As String)
                m_ConnectionId = Value
            End Set
        End Property
        Private m_ConnectionId As String
        Public Property UserName() As String
            Get
                Return m_UserName
            End Get
            Set(value As String)
                m_UserName = Value
            End Set
        End Property
        Private m_UserName As String
    End Class
End Namespace
Was it helpful?

Solution

You could also try with

If ConnectedUsers.Where(Function(x) x.ConnectionId = id).Count = 0 Then
    Console.WriteLine("bingo")
end if

Or force your ConnectedUsers list to an IEnumerable and call the correct Count method

if ConnectedUsers.AsEnumerable().Count(Function(x) x.ConnectionId = id) Then
    Console.WriteLine("bingo")
end if

OTHER TIPS

Use this:

Shared ConnectedUsers As New List(Of UserDetail)()
If ConnectedUsers.Count(Function(x) x.ConnectionId = id) = 0 Then
End If

I recommend using http://converter.telerik.com/ for converting c# to vb or vice versa.

But remember, that convert the code line by line, other wise, it will throw error.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top