我正在尝试向现有集合添加新行/值。但是在添加行之后它会显示相同的旧结果。
//代码
Using CustomActionWorkflow As New CustomActionWorkflow()
CustomActionWorkflow.WorkflowId = Me.WorkflowId
CustomActionWorkflow.CustomActionId = Me.CustomActionId
Me.CustomActionsController.CustomActionsWorkflowCollection.ToList().Add(CustomActionWorkflow)
End Using
我哪里错了?
答案 0 :(得分:1)
ToList()函数为您提供IEnumerable集合的新副本。您尝试添加到您没有参考的列表。
如果CustomActionsWorkflowCollection具有Add方法
,请尝试Me.CustomActionsController.CustomActionsWorkflowCollection.Add(CustomActionWorkflow)
或者如果可以设置集合
var list = Me.CustomActionsController.CustomActionsWorkflowCollection.ToList();
list.Add(CustomActionWorkflow);
Me.CustomActionsController.CustomActionsWorkflowCollection = list;
但是最后一个不是一个好的解决方案,因为创建了很多临时列表。