Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/24.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/17.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
.net 向集合添加行不起作用_.net_Vb.net_Collections - Fatal编程技术网

.net 向集合添加行不起作用

.net 向集合添加行不起作用,.net,vb.net,collections,.net,Vb.net,Collections,我正在尝试向现有集合添加新行/值。但在添加行之后,它会显示相同的旧结果 //代码 Using CustomActionWorkflow As New CustomActionWorkflow() CustomActionWorkflow.WorkflowId = Me.WorkflowId CustomActionWorkflow.CustomActionId = Me.CustomActionId Me.CustomActionsControll

我正在尝试向现有集合添加新行/值。但在添加行之后,它会显示相同的旧结果

//代码

Using CustomActionWorkflow As New CustomActionWorkflow()
        CustomActionWorkflow.WorkflowId = Me.WorkflowId
        CustomActionWorkflow.CustomActionId = Me.CustomActionId
        Me.CustomActionsController.CustomActionsWorkflowCollection.ToList().Add(CustomActionWorkflow)
End Using
我错在哪里?

ToList()函数提供IEnumerable集合的新副本。您试图添加到没有参考的列表中

如果CustomActionsWorkflowCollection具有Add方法,请重试

Me.CustomActionsController.CustomActionsWorkflowCollection.Add(CustomActionWorkflow)
或者是否可以设置集合

    var list = Me.CustomActionsController.CustomActionsWorkflowCollection.ToList(); 
list.Add(CustomActionWorkflow);
Me.CustomActionsController.CustomActionsWorkflowCollection = list;
但是最后一个不是一个很好的解决方案,因为它会创建很多临时列表。

ToList()函数提供IEnumerable集合的新副本。您试图添加到没有参考的列表中

如果CustomActionsWorkflowCollection具有Add方法,请重试

Me.CustomActionsController.CustomActionsWorkflowCollection.Add(CustomActionWorkflow)
或者是否可以设置集合

    var list = Me.CustomActionsController.CustomActionsWorkflowCollection.ToList(); 
list.Add(CustomActionWorkflow);
Me.CustomActionsController.CustomActionsWorkflowCollection = list;

但是最后一个不是一个好的解决方案,因为创建了很多临时列表。

什么是
CustomActionsWorkflowCollection
proeprty?@nemesv:它是一个属性集合。
CustomActionsWorkflowCollection
proeprty的类型?@nemesv:它是一个属性集合。你想我添加什么在不转换为列表的情况下?要给出完整答案,我们需要知道Me.CustomActionsController.CustomActionsWorkflowCollection
Me.CustomActionsController.CustomActionsWorkflowCollection=Me.CustomActionsController.CustomActionsWorkflowCollection.ToList()的类型。添加(CustomActionWorkflow)
无法工作,因为
列表。Add
具有返回类型
void
。是否要我添加而不转换为列表?要给出完整答案,我们需要知道me的类型。CustomActionsController.CustomActionsWorkflowCollection
me.CustomActionsController.CustomActionsWorkflowCollection=Me.CustomActionsController.CustomActionsWorkflowCollection.ToList().Add(CustomActionWorkflow)
将不起作用,因为
列表。Add
具有返回类型
void