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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T10:24:38+00:00 2026-05-16T10:24:38+00:00

part of the code: Dictionary<Calculation, List<PropertyValue>> result = new Dictionary<Calculation, List<PropertyValue>>(); while (reader !=

  • 0

part of the code:

Dictionary<Calculation, List<PropertyValue>> result = new Dictionary<Calculation, List<PropertyValue>>();
while (reader != null && reader.Read()) //it loops about 60000, and it will be bigger
{
    #region create calc and propvalue variables
    //...
    #endregion

    //this FirstOrDefault needs a lot of time
    tmpElementOfResult = result.Keys.FirstOrDefault(r => r.InnerID == calc.InnerID);
    if (tmpElementOfResult == null)
    {
        result.Add(calc, new List<PropertyValue> { propValue });
    }
    else
    {
        result[tmpElementOfResult].Add(propValue);
    }
}

Could you give me some idea how to make it faster, because now it’s approximately 25 sec 🙁 ?

  • 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-05-16T10:24:39+00:00Added an answer on May 16, 2026 at 10:24 am

    It sounds like you should have a dictionary from the type of calc.InnerID, instead of a Dictionary<Calc, ...>. That way you can do the lookup far more quickly. Do you actually need to store the Calc itself at all, or are you only interested in the ID?

    For example:

    Dictionary<Guid, List<PropertyValue>> result = 
        new Dictionary<Guid, List<PropertyValue>>();
    while (reader.Read())
    {
        // Work out calc
        List<PropertyValue> list;
        if (!result.TryGetValue(calc.InnerID, out list))
        {
             list = new List<PropertyValue>();
             result[calc.InnerID] = list;
        }
        list.Add(propValue);
    }
    

    Alternatively, if you can convert the reader to an IEnumerable<Calc> you could use:

    Lookup<Guid, PropertyValue> result = items.ToLookup(x => x.InnerID,
                                                        // Or however you get it...
                                                        x => x.PropertyValue);
    

    EDIT: It sounds like two Calc values should be deemed equal if they have the same InnerID, right? So override Equals and GetHashCode within Calc to refer to the InnerID. Then you can just use:

    Lookup<Calc, PropertyValue> result = items.ToLookup(x => x,
                                                        // Or however you get it...
                                                        x => x.PropertyValue);
    

    … or you can use code like the first snippet, but with a Dictionary<Calc, ...>:

    Dictionary<Calc, List<PropertyValue>> result = 
        new Dictionary<Calc, List<PropertyValue>>();
    while (reader.Read())
    {
        // Work out calc
        List<PropertyValue> list;
        if (!result.TryGetValue(calc, out list))
        {
             list = new List<PropertyValue>();
             result[calc] = list;
        }
        list.Add(propValue);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 530k
  • Answers 530k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer i'm not using the malsup plugin, but if i'm right,… May 16, 2026 at 11:36 pm
  • Editorial Team
    Editorial Team added an answer I come up with this solution: $(function() { $('.a').live('mouseover', function(e)… May 16, 2026 at 11:36 pm
  • Editorial Team
    Editorial Team added an answer Could it be that if you have multi byte characters,… May 16, 2026 at 11:36 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

The code: [1] private delegate void ThreadStatusCallback(ReceiveMessageAction action, Dictionary<int, List<string>> message); [2] Dictionary<int, List<string>>
I had a part of code that takes in lambda expressions at runtime, which
I have a function, that returns the next higher value of a Dictionary-Keys-List compared
This is a two part question: Part 1 First, dealing with calculating the entropy
Today I encountered this article about decimal expansion and I was instantaneously inspired to
I will be creating a project that will use dictionary lookups and inserts quite
I'm quite new to iphone programming and I want to do the following stuff:
I'm writing a tool, and the first part of that tool is to collect
I want to make a C# Dictionary in which the key is the string
Alright, I'm trying to pass a Dictionary, where key = int, and value =

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.