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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T08:36:14+00:00 2026-06-11T08:36:14+00:00

I have the code below which works for the purpose of what I need

  • 0

I have the code below which works for the purpose of what I need but I have an idea that it could be made faster. Please let me know if this code can be improved in any way…

The main issue is that I need to query “data” several time. I just need to make sure that there is no shortcut that I could have used instead.

data= GetData()// this return ILookup<Tuple(string, string, string),string>
foreach (var v0 in data)
{
    if (v0.Key.Item3 == string.Empty)
    {
        //Get all related data
        var tr_line = data[v0.Key];
        sb.AppendLine(tr_line.First());

        foreach (var v1 in data)
        {
            if (v1.Key.Item2 == string.Empty && v1.Key.Item1 == v0.Key.Item1)
            {
                var hh_line = data[v1.Key];
                sb.AppendLine(hh_line.First());

                foreach (var v2 in data)
                {
                    if (v2.Key.Item1 == v0.Key.Item1 && v2.Key.Item2 != string.Empty && v2.Key.Item3 != string.Empty)
                    {
                        var hl_sl_lines = data[v2.Key].OrderByDescending(r => r);
                        foreach (var v3 in hl_sl_lines)
                        {
                            sb.AppendLine(v3);
                        }
                    }
                }
            }
        }
    }
 } 
  • 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-11T08:36:15+00:00Added an answer on June 11, 2026 at 8:36 am

    Neater, more linq:

            var data = GetData();
    
            foreach (var v0 in data)
            {
                if (v0.Key.Item3 != string.Empty) continue;
    
                //Get all related data 
                var tr_line = data[v0.Key];
                sb.AppendLine(tr_line.First());
    
                var hhLines = from v1 in data
                              where v1.Key.Item2 == string.Empty &&
                                    v1.Key.Item1 == v0.Key.Item1
                              select data[v1.Key];
    
                foreach (var hh_line in hhLines)
                {
                    sb.AppendLine(hh_line.First());
    
                    var grouping = v0;
                    var enumerable = from v2 in data
                                     where v2.Key.Item1 == grouping.Key.Item1 &&
                                           v2.Key.Item2 != string.Empty &&
                                           v2.Key.Item3 != string.Empty
                                     select data[v2.Key].OrderByDescending(r => r)
                                     into hl_sl_lines from v3 in hl_sl_lines select v3;
    
                    foreach (var v3 in enumerable)
                    {
                        sb.AppendLine(v3);
                    }
                }
            }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following code below which works, but I want to insert values
I have this code below which works fine but seems unnecessary as it loops
I have my code below which works well but i also want to move
I have the code below, which works fine it can be viewed for an
Below is the code I have for sending email which works great. /* *
I have a function(please see code below) which reads some data from the web.
I have the code below, which works lovely and does EXACTLY what I want
I have some jQuery code which works great in Firefox and Chrome, but does
I have a sample code snippet below which works just fine (I trimmed the
I have the code below which I use clone() and live() . The code

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.