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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T23:01:24+00:00 2026-06-13T23:01:24+00:00

I want to initialize a list with an object and a list of objects

  • 0

I want to initialize a list with an object and a list of objects in that specific order. Currently, I am doing:

List<MyObject> list = new List<MyObject>();
list.Add(object1); // object1 is type MyObject
list.AddRange(listOfObjects); // listOfObjects is type List<MyObject>

I was hoping to consolidate that into an initialization statement (the syntax is wrong of course):

List<MyObject> newList = new List<MyObject>() { object1, listOfObjects };

Is there a way to do this concisely?

  • 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-13T23:01:25+00:00Added an answer on June 13, 2026 at 11:01 pm

    If the order of the elements is not important, you can use:

    List<MyObject> newList = new List<MyObject>(listOfObjects) { object1 };
    

    This works by using the List<T> constructor which accepts an IEnumerable<T>, then the collection initializer to add the other items. For example, the following:

    static void Main()
    {
        int test = 2;
        List<int> test2 = new List<int>() { 3, 4, 5 };
        List<int> test3 = new List<int>(test2) { test };
    
        foreach (var t in test3) Console.WriteLine(t);
    
        Console.ReadKey();
    }
    

    Will print:

    3
    4
    5
    2
    

    Note that the order is different than your original, however, as the individual item is added last.

    If the order is important, however, I would personally just build the list, placing in your first object in the initializer, and calling AddRange:

    List<MyObject> newList = new List<MyObject> { object1 };
    newList.AddRange(listOfObjects);
    

    This makes the intention very clear, and avoids construction of temporary items (which would be required using LINQ’s Concat, etc).

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

Sidebar

Related Questions

I am new to LINQ. playerData is a list<DataAccess.Team> and I want to initialize
How can I loop through a List of type Object? List<object> countries = new
I'm a looking to initialize an array/list of objects that are not empty --
I want to create a 'File' object that returns 'Line' objects when the ReadLine()
I want to create a web method that accepts a List of custom objects
I want to have some kind of single list that is initialized in a
I want to initialize an array and then initialize a pointer to that array.
Window c# Desktop Application I want to initialize a DataRow object with the selected
I have a list of objects and I want to sent it thought TCP
I'm creating a object of hash in order to write a little script that

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.