help to convert c# anonymous to vb.net
Please help me to convert this below code to vb.net. I have no idea to convert from anonymous method to vb.net. I'm currently using VS2010.
    public void DoWork(CustomObject obj)
    {
        var linq = (from s in s开发者_如何学Gotorages
                     where s.Key == obj.Key
                     select s.Value).ToList();
        Action<ICustomService> act =
            delegate(ICustomService service)
            {
                service.ChangeValue(obj);
            };
        linq.ForEach(act);
    }
Thank you in advance.
Pure C# Developer
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
Try using this online c# to vb.net code conversion:
http://www.developerfusion.com/tools/convert/csharp-to-vb/
SharpDevelop is a free IDE for dotnet that supports several automatic sourcecode translations i.e. C# to VB.NET, IronRuby or IronPyton
For your example it produced
'
' * 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
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
 
         加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论