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

  • SEARCH
  • Home
  • 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 8623841
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T07:22:47+00:00 2026-06-12T07:22:47+00:00

I have two generic list that have been unioned. Say listA and listB, both

  • 0

I have two generic list that have been unioned. Say listA and listB, both of type List<SomeType>.

listA.Union(listB);

The unioned set is of type System.Linq.Enumerable.UnionIterator<string>, which isn’t the same as List<SomeType>.

I have tried casting:

listA.Union(listB).ToList<SomeType>();

and

(List<SomeType>)listA.Union(listB);

Both fail. I tried to access ForEach(), thinking I could add the result to a new list. .Foreach() isn’t available.

I could use a traditional foreach and add each item to a List<SomeType> variable. However, is there a lambda statement that can do the conversion in one line, assigning to a variable of type List<SomeType>?

  • 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-06-12T07:22:49+00:00Added an answer on June 12, 2026 at 7:22 am

    You don’t have to explicitly cast the List in ToList method. If both the list are of same type, you can simply do ToList in the end to get a List of the same type.

    List<MyClass> listA = new List<MyClass>();
    List<MyClass> listB = new List<MyClass>();
    List<MyClass> temp = listA.Union(listB).ToList(); //Just do ToList at the end. 
    

    Explicitly specifying the type in ToList method should work as well. I am not sure why its not working.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two threads, a producer thread that places objects into a generic List
I have an interface that has a generic method with two type parameters. I
Let's say I have two generic lists of the same type. How do I
I have two generic lists of type T. Both lists contain same type, and
I have a list-generic that has a property (class type). I need a sort
If I have two generic lists, List, and I want to merge all the
I have a two generic abstract types: Entity and Association . Let's say Entity
I'm having trouble grasping generic methods. I have two classes that are generated (they
I have a Generic Base Class that I want to allow one of two
I have two separate views that both show multiple lists of values. Both views

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.