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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T04:16:54+00:00 2026-06-16T04:16:54+00:00

All, I want to create an object array foo[] , where the constructor for

  • 0

All, I want to create an object array foo[], where the constructor for Foo is

public Foo(string name, string discription){}

I have a database object which has a structure (not incuding stored procedures, functions or views for simplicity) like

public class Database 
{
    public string name { get; set; }
    public string filename { get; set; }
    public List<Table> tables { get; set; }

    public Database(string name, string filename)
    {
        this.name = name;
        this.filename = filename;
    }
}

protected internal class Table 
{
    public string name { get; set; }
    public List<Column> columns { get; set;}

    public Table(string name, List<Column> columns)
    {
        this.name = name;
        this.columns = columns;
    }
}

protected internal class Column
{
    public string name { get; set; }
    public string type { get; set; }

    public Column(string name, string type, int maxLength, 
                  bool isNullable)  
    {
        this.name = name;
        this.type = type;
    }
}

I would like to know the quickest way to add Column and Table information to the Foo[] object array?

Clearly I can do

List<Foo> fooList = new List<Foo>();
foreach (Table t in database.tables)
{
    fooList.Add(new Foo(t.Name, "Some Description"));
    foreach (Column c in t.columns)
        fooList.Add(new Foo(c.Name, "Some Description"));
}
Foo[] fooArr = fooList.ToArray<Foo>();

But is there a quicker way? Clearly LINQ is likely to be slower for a query that does a simalar operation, but I care allot about speed here so any advice would be appreciated. Perhaps the use of a HashSet would be the way to go as there will not be duplicate entries…

Thanks for your time.

  • 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-16T04:16:55+00:00Added an answer on June 16, 2026 at 4:16 am

    I would say change your foreach loop to for loop, as discussed here In .NET, which loop runs faster, 'for' or 'foreach'?
    Datastructure wise, you do need mutable structure, unless you know exactly how many records you will be inserting into fooList, then you can use Array instead of list. According to the answer of the foreach vs for-loop question, assuming it’s correct, for loops on List are a bit more than 2 times cheaper than foreach loops on List, and Looping on array is around 2 times cheaper than looping on List.

    So 2 improvement would be:

    1. change foreach to for

    2. use linq to compute the length for the array
      as per @Tim Schmelter, and change List to Array

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

Sidebar

Related Questions

I want to have one directory for all object files and create Common.pri file
I want to create the dictionary of all the ViewModels. public static Dictionary<string, WeakReference>
I want to create JSF table which has select all button and check box
I have an array which contains lots of info like lat,lon,city name etc.But all
Suppose I have an object that looks like: public class Obj { String foo;
I want to create a constructor function in javascript, which has a .prototype property
I want to create a string in JavaScript that contains all ascii characters. How
I want to create a logger which logs all my messages sent to System.out
I have a json object array. I want to search the array and for
I want to create a Java method, which accepts an inputArray = Object[n][] ,

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.