帮助将c#匿名转换为vb.net

时间:2011-03-26 17:26:05

标签: c# vb.net

请帮我将以下代码转换为vb.net。我不知道从匿名方法转换为vb.net。我目前正在使用VS2010。

    public void DoWork(CustomObject obj)
    {
        var linq = (from s in storages
                     where s.Key == obj.Key
                     select s.Value).ToList();

        Action<ICustomService> act =
            delegate(ICustomService service)
            {
                service.ChangeValue(obj);
            };

        linq.ForEach(act);
    }

提前谢谢。

Pure C#Developer

4 个答案:

答案 0 :(得分:4)

Public Sub DoWork(ByVal obj As CustomObject)

    Dim values = (From s In storages
                 Where s.Key = obj.Key
                 Select s.Value).ToList()

    values.ForEach(Sub(service As ICustomService) service.ChangeValue(obj))

End Sub

答案 1 :(得分:0)

尝试使用此在线c#进行vb.net代码转换:

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

答案 2 :(得分:-1)

Public Sub DoWork(ByVal obj As CustomObject)
    Dim linq = storage.Where(Function(s) s.Key = obj.Key).[Select](Function(s) s.Value).ToList()

    Dim act As Action(Of ICustomService) = Sub(service As ICustomService)
                                               service.ChangeValue(obj)
                                           End Sub

    linq.ForEach(act)
End Sub

答案 3 :(得分:-1)

SharpDevelop是一个免费的dotnet网站,支持多种自动源代码翻译,即C#到VB.NET,IronRuby或IronPyton

为您的例子制作

'
' * Created by SharpDevelop.
' * User: k3b
' * Date: 26.03.2011
' * Time: 18:44
' * 
' * To change this template use Tools | Options | Coding | Edit Standard Headers.
' 

Imports System

Namespace DefaultNamespace
    ''' <summary>
    ''' Description of Class1.
    ''' </summary>
    Public Class Class1
        Public Sub New()
        End Sub
        Public Sub DoWork(obj As CustomObject)
            Dim linq = (From s In storages Where s.Key = obj.Keys.Value).ToList()

            Dim act As Action(Of ICustomService) = Function(service As ICustomService) Do
                service.ChangeValue(obj)
            End Function

            linq.ForEach(act)
        End Sub
    End Class
End Namespace