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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T14:39:58+00:00 2026-06-17T14:39:58+00:00

I am trying to select text from a collection that is three of four

  • 0

I am trying to select text from a collection that is three of four deep.

RootObject has a List<ResourceSet> resourceSets

The resourceSets has a List<Resources> resources

The resources has a List<RouteLeg> routeLegs

The routLegs has a List<ItineraryItem> itineraryItems

The each routeLeg contains and object called ItineraryItem and in that object there is a text property.

I am trying to pull out a list of all the text properties on the routeLeg object. As you can see it is nested pretty deep. I can obviously do this in nested loops..(as shown below) but want something cleaner using Linq to Objects but I am having trouble with the multiple nesting.

  ResourceSet testst = new ResourceSet();
            ResourceSet rs;          
            StringBuilder sb = new StringBuilder();

            for (int i = 0; i < _Result.resourceSets.Count; i++)
            {
                rs = _Result.resourceSets[i];


                for (int j = 0; j < rs.resources.Count; i++)
                {

                    Resource rec = rs.resources[j];

                    string test = rec.distanceUnit;

                    for (int k = 0; k < rec.routeLegs.Count; k++)
                    {
                        RouteLeg rl = rec.routeLegs[k];

                        for (int l = 0; l < rl.itineraryItems.Count; l++)
                        {
                            ItineraryItem ii = rl.itineraryItems[l];                           
                            sb.Append(ii.instruction.ToString());
                        }
                    }

                }
            }
  • 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-17T14:40:00+00:00Added an answer on June 17, 2026 at 2:40 pm

    You can use SelectMany to fetch the internal items:

    var items = result.resourceSets
                      .SelectMany(rs => rs.resources)
                      .SelectMany(res => res.routeLegs)
                      .SelectMany(rl => rl.itineraryItems)
    foreach(var x in items)
        sb.Append(x.instruction.ToString());
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to select the text from the name attribute of the anchor element
I am trying to select three values from xml document. I want to get
I am trying to select the text from a text box and pass it
I'm trying to use Command.Prepare with a CommandType.Text query that has a single input
I am trying to do something like this: select char_length(select text_field from table where
I'm trying to select all text in-between following a specific pattern: Sample Text: by
alt text http://www.freeimagehosting.net/image.php?a55fa98f01.jpg Hi I am trying to use a HTML select box with
I trying to select all li elements at second level of the list add
In trying to select elements that have any attributes, the following throws a jQuery
When trying to select fields from a subquery if ANY of the subqueries do

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.