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 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

Related Questions

Part of my code goes like this: while(1){ my $winmm = new Win32::MediaPlayer; $winmm->load('1.mp3');
I have the following code snippet: Dictionary<int, List<string>> likeListDict = new Dictionary<int, List<string>>(); List<string>
I am trying to learn and writting this part of code. while testing few
I'm studying data structures (List, Stack, Queue), and this part of code is confusing
The code: [1] private delegate void ThreadStatusCallback(ReceiveMessageAction action, Dictionary<int, List<string>> message); [2] Dictionary<int, List<string>>
Problem part of the code: while counter < length: if something: else: for key,value
I added multithreading part to my code . public class ThreadClassSeqGroups { public Dictionary<string,
I have this part of code in my functions.php: function cc_admin_enqueue_scripts($hook) { $file_dir=get_bloginfo('template_directory'); wp_enqueue_script('media-upload');
I want to test my part of code that returns the users password question.
I'm having a problem with a part of code. It should work,since it is

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.