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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T21:36:24+00:00 2026-06-01T21:36:24+00:00

Lets say I have something like this: MySomething element1 = new MySomething(stuff); MySomething element2

  • 0

Lets say I have something like this:

MySomething element1 = new MySomething(stuff);
MySomething element2 = new MySomething(stuff);
MySomething element3 = new MySomething(stuff);
MySomething element4 = new MySomething(stuff);
MySomething element5 = new MySomething(stuff);
//and so on...

Now lets say I have a list or something somewhere and I would like to add all of the elements to the list. They I have to to do:

myList.add(element1);
myList.add(element2);
//and so on...

That would take long. And If I would have 100+ elements, well it takes forever ^^ Is there a faster way to add that much of created ‘elements’ into a list? I know

myList.add(new MySomething(stuff));

But let say, the elements were already created like here in example. How to add them in c# into a list faster? Thank you 🙂

Edit: ok and I have to say, the names are not always element1-100 its sometime element23, element454 and so on. The number after element is not always sequential. And yes they are all of the same type.

  • 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-01T21:36:25+00:00Added an answer on June 1, 2026 at 9:36 pm

    If they are all of the same type and you know how many you need just use a loop to create an array initially:

    MySomething[] items = new MySomething[N];
    for(int i = 0; i < N; i++)
    {
        items[i] = new MySomething(stuff);
    }
    

    later, add all items to the list:

    list.AddRange(items);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say I have something like this: $db=new PDO($dsn); $statement=$db->query('Select * from foo'); while
Here is the Problem: Lets say I have something like this: <div id=leftcontainer> <div
Lets say I have something like this: http://gyazo.com/642987562175afc6d11a962762327744.png?1329570534 Basically, the user fills out this
So lets say I have a table that looks something like this: ItemName ProductType
Lets say I have something like this: private CancellationTokenSource myToken; public void MyMyMethod() {
Lets say I have something like this uid tag 1 HeLLo 2 heLLO 3
Lets say i have something like this: This is file tree.py: class leaf(): def
Lets say I have something like this: <tr> <td><input type=text /></td> <td>Somevalue</td> <td><intput type=text
Lets say I have something like this: public ActionResult Test(SomeModel m) { try {
Lets say I have a custom data type that looks something like this: public

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.