.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.CustomActionsWorkflowCollectionMe.CustomActionsController.CustomActionsWorkflowCollection=Me.CustomActionsController.CustomActionsWorkflowCollection.ToList()的类型。添加(CustomActionWorkflow)
无法工作,因为列表。Add
具有返回类型void
。是否要我添加而不转换为列表?要给出完整答案,我们需要知道me的类型。CustomActionsController.CustomActionsWorkflowCollectionme.CustomActionsController.CustomActionsWorkflowCollection=Me.CustomActionsController.CustomActionsWorkflowCollection.ToList().Add(CustomActionWorkflow)
将不起作用,因为列表。Add
具有返回类型void
。