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 8237023
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T19:19:58+00:00 2026-06-07T19:19:58+00:00

I would like to add new iEnumerable object to original one. Can I do

  • 0

I would like to add new iEnumerable object to original one. Can I do this updating original object in extenstion method like following?

public static void AddItems<TSource>(this IEnumerable<TSource> orginalColl,    
IEnumerable<TSource> collectionToAdd)
{
foreach (var item in collectionToAdd)
{
    orginalColl.ToList<TSource>().Add(item);             
}             
}

I am calling like this: OrgCollecation.AddItems(newCollection).
But this does not seems to work. Any idea?

  • 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-07T19:19:59+00:00Added an answer on June 7, 2026 at 7:19 pm

    An IEnumerable[<T>] is not intended for adding. You can concatenate (generating a new sequence), but that doesn’t change the original sequence (/list/array/etc). You can do that with Enumerable.Concat, i.e. return orginalColl.Concat(...). But emphasis: this does not update the original collection.

    What you could do would be to cast to IList[<T>] or similar, but that would be abusive (and will only work for some scenarios, not all). It won’t work, for example, for anything that is based on an iterator block (or any other IEnumerable<T> that is not also an IList<T>) – for example it won’t work on someSource.Where(predicte).

    If you expect to change the source, then you should be passing in something like IList[<T>]. For example:

    public static void AddItems<TSource>(this IList<TSource> orginalColl,
        IEnumerable<TSource> collectionToAdd)
    {
        foreach (var item in collectionToAdd)
        {
            orginalColl.Add(item);             
        }             
    }
    

    (btw, AddRange would be an alternative name for the above, to match List<T>.AddRange)

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

Sidebar

Related Questions

PHP/MySQL (CodeIgniter) I would like to add new interest_keywords in the exist database value.
I have a dataframe and would like to add a new column where the
Using the .NET System.ServiceModel.Syndication classes... I would like to add a new SyndicationElementExtension to
I would like to add some paragraphs or new lines or words dynamically but
I would like restfully add a parameter to the new named path. So for
I would like to be able to add a new SQL LOGIN and name
I'm new in web development and would like to add a feature to a
I would like to return an ExpandoObject from a WebMethod, like this: [WebMethod] public
I would like a Covariant collection whose items can be retrieved by index. IEnumerable
I have an IEnumerable<KeyValuePair<string,string>> , from which I would like, ideally, an anonymous object

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.