Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3226766
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T16:29:44+00:00 2026-05-17T16:29:44+00:00

I am using using Microsoft .NET Framework 4.0. I have run into this using

  • 0

I am using using Microsoft .NET Framework 4.0.

I have run into this using Aggregate on a Dictionary<T, List<T>> to extract the set of type T values used across all type List<T> lists in the dictionary. Here is the simplest case I could come up with that exhibits the same behaviour.

First, as the documentation states, the following does work:

var set = new HashSet<int>();
var list = new LinkedList<int>();
var newSet = set.Union(list);

That is, I can call Union on a HashSet with a List as the argument (since it implements IEnumerable).

Whereas, the equivalent expression within a Func argument of the LINQ Aggregate expression produces an error (precompiler at least):

new List<int>[] { new List<int>() }.Aggregate(new HashSet<int>(), (acc, list) => acc.Union(list));

It expects the argument of Union to be HashSet, and will cooperate if it is given one, contrary to its behaviour outside LINQ/Func expressions.

The real world example I was using when I came across the problem was:

public AdjacencyListGraph(Dictionary<TVertex, LinkedList<TVertex>> adjacencyList)
{
    var vertices = adjacencyList.Aggregate(new HashSet<TVertex>(),
    (vertices, list) => vertices.Union(list.Value));
}

Which complains that it cannot convert IEnumerable<TVertex> to HashSet<TVertex>…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T16:29:45+00:00Added an answer on May 17, 2026 at 4:29 pm

    The problem actually lies in trying to replace the accumulator type of HashSet with the IEnumerable, .Union method doesn’t add items to HashSet, but returns the new IEnumerable on the resulting union.

    You should change your code to the following:

        // select from keys
        var vertices = new HashSet<TVertex>(adjacencyList.Keys);
    

    or

        // select from values
        var vertices = new HashSet<TVertex>(adjacencyList.SelectMany(dictEntry => dictEntry.Value));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a .NET WinForms application that I've converted into a COM dll using
I am using Microsoft Visual Web Developer 2008 Express. I've made an ASP.NET MVC
I have a program i frequently use that is made with .NET. This program
I have been using Anthem.NET in ASP.NET 2.0 projects for a few side projects
I'm using VB.NET and the .NET 3.5 framework. I am trying to automate word
Im using Microsoft ASP.NET 2.0 Provider to setup USERS, ROLES and MEMBERSHIP for my
I am using mshtml for html parsing. (version 7.0.3300.0, C:\Program Files\Microsoft.NET\Primary Interop Assemblies\Microsoft.mshtml.dll). HTMLDocumentClass
Using Microsoft SQL Server's database mirroring capability, can the mirroring occur between two clusters?
I am using Microsoft Access 2007 to move and massage some data between two
I'm using Microsoft.XMLHTTP to get some information from another server from an old ASP/VBScript

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.