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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T02:45:55+00:00 2026-06-12T02:45:55+00:00

var runnerElement = xDox.Descendants(User) .SingleOrDefault(u => u.Element(Name).Value == David); if (runnerElement != null) {

  • 0
var runnerElement = xDox.Descendants("User")
      .SingleOrDefault(u => u.Element("Name").Value == "David");

if (runnerElement != null)
{
    var result = runnerElement.Descendants("Runners")
      .Select(a => new
        {

            Date = DateTime.Parse(a.Element("Date").Value),
            MyLength = int.Parse(a.Element("Length").Value)
            City = a.Element("City").Value,
        })
      .Where(a => a.Date >= DateTime.Parse("3/29/2012")
                && a.Date <= DateTime.Parse("8/29/2012"))

      .GroupBy(a => a.City)
      .Select(g => new {City = g.Key, Avg = g.Average(x => x.MyLength)});
}

How would you loop through this data so it can give me an output something like this

User:David
Date:3/29/2012 to 8/29/2012
Average Distance in Paris : //Data
Average Distance in Madrid: //Data

I try to clarified my code a little bit more..

  • 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-12T02:45:56+00:00Added an answer on June 12, 2026 at 2:45 am

    To correct my previous answer, it should have a method, assume GetData with relevant input, so you can use StringBuilder to build string:

    public string GetData(string userName, DateTime fromDate, DateTime toDate)
    {
         var userElement = xDox.Descendants("User")
                .SingleOrDefault(u => u.Element("Name").Value == userName);
    
        var builder = new StringBuilder();
    
        if (userElement != null)
        {
            var result = userElement.Descendants("Attempts")
                .Select(a => new
                    {
                        Place = a.Element("Place").Value,
                        Date = DateTime.Parse(a.Element("Date").Value),
                        Distance = int.Parse(a.Element("Distance").Value)
                    })
    
                .Where(a => a.Date >= fromDate
                            && a.Date <= toDate)
    
                .GroupBy(a => a.Place)
                .Select(g => new {Place = g.Key, Avg = g.Average(x => x.Distance)});
    
            builder.AppendFormat("User:{0}", userName);
            builder.AppendLine();
    
            builder.AppendFormat("Date:{0} to {1}", fromDate, toDate);
            builder.AppendLine();
    
            foreach (var item in result)
            {
                builder.AppendFormat("Average Distance in {0}: {1}", 
                                                   item.Place, item .Avg);
                builder.AppendLine();
            }
        }
    
        return builder.ToString();
    }
    

    In order to use:

    var fromDate = DateTime.Parse("8/30/2012");
    var toDate = DateTime.Parse("10/1/2012");
    
    string result = GetData("David", fromDate, toDate);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

var queueitem = context.CrawlerQueues. Select(cq => new{cq.Guid,cq.Result}). SingleOrDefault(cq => cq.Guid == guid); Is above
var ref1 = new Firebase(http://gamma.firebase.com/myuser/123,456); ref1.set(123,456); var on1 = ref1.on(value, function(snapshot) { console.log(snapshot.val()); });
var result = null; function setSendButton(userInput){ var clicked=userInput; result = <%=mb.myMethod(clicked)%>; } where myMethod
var chart; var d = new Array(); function click() { d = document.getElementById('graph:hi').value; alert(d);
var xEle = new XElement(ContentDetails, from emp in _lstContents select new XElement(Contents, new XAttribute(key,
var rinlinejQuery = / jQuery\d+=(?:\d+|null)/g, html: function( value ) { if ( value ===
var longitudeArray = new Array(<?php $result = count($longitudeArray); if ($result > 1){ echo implode(',',
var idParam = new SQLiteParameter(@idParam, SqlDbType.Text) { Value = insertData.ID }; var userIdParam =
var search= document.getElementById('appMenu').value document.location.href= '${createLink(controller: 'application' , action:'ajaxAppSearch', params: ['query': search])}' The element appMenu
var x = '#google'; // or '@google' or '%google' var pattern = new RegExp('(^|\\s)'

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.