【发布时间】:2021-02-23 16:43:55
【问题描述】:
我有一个包含多个“面板页面”的“面板”模型。我想获取所有面板的列表,并用各自的“面板页面”填充每个面板。
这是我目前的代码(有效):
public IEnumerable<DynamicCustomPanel> GetCustomPanels()
{
var customPanels = _customPanelService.GetDynamicCustomPanels();
var dynamicCustomPanels = customPanels.ToList();
foreach (var customPanel in dynamicCustomPanels.ToList())
{
var customPanelPages = _customPanelPageService.GetCustomPanelPages(customPanel.PanelGUID.ToString());
customPanel.CustomPanelPages = customPanelPages;
}
return dynamicCustomPanels;
}
如何以最少的行数做到这一点?
【问题讨论】:
-
How do I do this in an minimal amount of lines?是否存在问题,可能是维护或性能问题? -
摆脱那些额外的
ToList()电话。它们会消耗内存。
标签: c# linq .net-core ienumerable enumeration