简体   繁体   English

如何将C#转换为vb.net

[英]how to convert c# to vb.net

I would you convert this from C# code in vb.net 我想将其从vb.net中的C#代码转换为

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/ 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. " 但是无法正常运行,Visual Studio告诉我(这部分错误'ConnectedUsers.Count')“'公共ReadOnly属性计数为整数'没有参数,并且无法为它的返回值建立索引。”

Thank you in advance for your help 预先感谢您的帮助

Edit 1 I put it the declaration 编辑1我把它声明

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

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. 我建议使用http://converter.telerik.com/将c#转换为vb,反之亦然。

But remember, that convert the code line by line, other wise, it will throw error. 但是请记住,逐行转换代码,否则将引发错误。

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 或者将您的ConnectedUsers列表强制为IEnumerable并调用正确的Count方法

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM