Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/296.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C#到VB.Net的转换问题_C#_Vb.net_Visual Studio 2010_C# To Vb.net - Fatal编程技术网

C#到VB.Net的转换问题

C#到VB.Net的转换问题,c#,vb.net,visual-studio-2010,c#-to-vb.net,C#,Vb.net,Visual Studio 2010,C# To Vb.net,当将下面这行从C#转换为VB.Net时,我得到 表达式不产生值 C# VB.NET query.ToList().ForEach(Function(ti) cat.Add(ti)) C#代码: 将有问题的行更改为该行: query.ToList().ForEach(Sub(ti) cat.Add(ti)) 这是必要的,因为VB.NET中的Action(Sub(T))和Func(Function(T))有单独的语法(但在C#中没有)。我编辑了您的问题,以便更清楚错误在哪里,您应该尝试在问题

当将下面这行从C#转换为VB.Net时,我得到

表达式不产生值

C#

VB.NET

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

C#代码:


将有问题的行更改为该行:

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

这是必要的,因为VB.NET中的
Action
Sub(T)
)和
Func
Function(T)
)有单独的语法(但在C#中没有)。我编辑了您的问题,以便更清楚错误在哪里,您应该尝试在问题中只包含相关的信息
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);
}
  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
query.ToList().ForEach(Sub(ti) cat.Add(ti))