sviluppocsharp
sviluppocsharp

Reputation: 161

how to convert c# to vb.net

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

Upvotes: 1

Views: 1114

Answers (2)

Amit Joki
Amit Joki

Reputation: 59232

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.

Upvotes: 4

Steve
Steve

Reputation: 216273

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

Upvotes: 4

Related Questions