What is the most effective way to find a pool of two collections?

public IEnumerable<SummaryItem> GetSummaryData(SummarySettings settings)
{
   return GetSummaryReportData(startTime, endTime, settings.AgentIds);
}

After I wrote my code, I realized what I need to add idsto settings.AgentIds.

So, I do the following

public IEnumerable<SummaryItem> GetSummaryData(SummarySettings settings)
{
    if (settings.LabelIds != null && settings.LabelIds.Any())
    {
       var labelGroups = _agentsGroupsStorage.Values.Where(x => settings.LabelIds.Contains(x.Id));
       var labelAgentIds = labelGroups.SelectMany(x => x.AgentIds); // IEnumerable<Guid>

       settings.AgentIds = new GuidCollection(labelAgentIds.Union(settings.AgentIds).ToList());
    }

   return GetSummaryReportData(startTime, endTime, settings.AgentIds);
}

How can I improve my algorithm for combining two collections?

Maybe without creation new GuidCollection? Or do I need to use Aggregate, but not Union?

-1
source share
1 answer

Here is an example implementation of the Union:

public IEnumerable<T> Union(this IEnumerable<T> left, IEnumerable<T> right)
{
    var hs=new Hashset<T>(left);
    for(var item in right)
    {
        hs.Add(item);
    }
    return hs;
}

, . -, . , - , , , .

+3

Source: https://habr.com/ru/post/1608977/


All Articles