C# to VB.Net conversion issue

c#, c#-to-vb.net, vb.net, visual-studio-2010

Solution

Change the problematic line to that one:

query.ToList().ForEach(Sub(ti) cat.Add(ti)) 

That's necessary because there is a separate syntax for `Action<T>` (`Sub(T)`) and `Func<T>` (`Function(t)`) in VB.NET (but there is not in C#).

Problem

when converting the following line from C# to VB.Net I get Expression does not produce a value C# ``` query.ToList().ForEach(ti => cat.Add(ti)); ``` VB.NET ``` query.ToList().ForEach(Function(ti) cat.Add(ti)) ``` C# code : ``` void MainWindow_Loaded(object sender, RoutedEventArgs e) { new DesignerMetadata().Register(); var toolbox = new ToolboxControl(); var cat = new ToolboxCategory("Standard Activities"); var assemblies = new List<Assembly>(); assemblies.Add(typeof(Send).Assembly); assemblies.Add(typeof(Delay).Assembly); assemblies.Add(typeof(ReceiveAndSendReplyFactory).Assembly); var query = from asm in assemblies from type in asm.GetTypes() where type.IsPublic && !type.IsNested && !type.IsAbstract && !type.ContainsGenericParameters && (typeof(Activity).IsAssignableFrom(type) || typeof(IActivityTemplateFactory).IsAssignableFrom(type)) orderby type.Name select new ToolboxItemWrapper(type); query.ToList().ForEach(ti => cat.Add(ti)); toolbox.Categories.Add(cat); Grid.SetColumn(toolbox, 0); Grid.SetRow(toolbox, 1); LayoutGrid.Children.Add(toolbox); } ``` I want Vb.net conversion. when i converted this code in vb.net getting error in query.ToList().ForEach(Function(ti) cat.Add(ti)) this line .error is Expression does not produce a value. Converted VB.NET code ``` Private Sub MainWindow_Loaded(ByVal sender As Object, ByVal e As RoutedEventArgs) Dim metadata = New DesignerMetadata() metadata.Register() 'Create the ToolBoxControl Dim toolbox = New ToolboxControl() 'Create a collection of category items Dim cat = New ToolboxCategory("Standard Activities") Dim assemblies = New List(Of Assembly)() assemblies.Add(GetType(SendAndReceiveReplyFactory).Assembly) assemblies.Add(GetType(Delay).Assembly) assemblies.Add(GetType(ReceiveAndSendReplyFactory).Assembly) Dim query = _ From asm In assemblies From type In asm.GetTypes() _ Where type.IsPublic AndAlso Not type.IsNested AndAlso Not type.IsAbstract AndAlso Not type.ContainsGenericParameters AndAlso (GetType(Activity).IsAssignableFrom(type) OrElse GetType(IActivityTemplateFactory).IsAssignableFrom(type)) _ Order By type.Name Select New ToolboxItemWrapper(type) query.ToList().ForEach(Function(ti) cat.Add(ti)) toolbox.Categories.Add(cat) Grid.SetColumn(toolbox, 0) Grid.SetRow(toolbox, 1) LayoutGrid.Children.Add(toolbox) End Sub ```

Original source