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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T17:07:05+00:00 2026-06-13T17:07:05+00:00

I have a problem with looping through a set of XElements . The behavior

  • 0

I have a problem with looping through a set of XElements. The behavior is not what I expected.

A short re-written version of my code, so you can easily get my problem (console app in C#)

IEnumerable<XElement> q = from c in xml.Descendants(aw + "wd") 
                          where (....) 
                          select c;    
...

//--------------------------------------------------------------------    
IEnumerable<XElement> currRow = q.OrderBy(yyy => (int)yyy.Attribute("t"));

int xValue = 10;

currRow = currRow.Where(yyy => (int)yyy.Attribute("t") < xValue);
xValue = 20; 
//Here, the currRow gets a new value automatically. I don't want this!


//--------------------------------------------------------------------
//This is want i want to acheive: 

IEnumerable<XElement> currRow = q.OrderBy(yyy => (int)yyy.Attribute("t")); 

int xValue = 10;

currRow = currRow.Where(yyy => (int)yyy.Attribute("t") < xValue);
//do somthing with currRow

xValue = 20; 
currRow = currRow.Where(yyy => (int)yyy.Attribute("t") < xValue);
//do somthing else with currRow

xValue = 30; 
currRow = currRow.Where(yyy => (int)yyy.Attribute("t") < xValue);
// etc....

Any ideas?

  • 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-13T17:07:06+00:00Added an answer on June 13, 2026 at 5:07 pm
    currRow.Where(...)
    

    Will create a query that will be executed when used.
    If you want the result directly (and omitting any references/query to be screwed up) convert it to a list.

    currRow.Where(...).ToList()
    

    The reason why you should to this is because the value you use in your where statement isn’t seen as a constant within the query but a reference to the variable you used. If you change the variable, you possibly changed the outcome of the query.
    If you call .ToList() the query is executed with the value of the variable on that moment. The result is gathered and is ‘permanent’ in such way that the query which was made to create the result won’t be influencing the result any more when the value of the variable used in the query changes.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Am try to looping through a database result set, the problem is that i
I have a problem with Hibernate Validator 3.1.0.GA not looking up custom validation messages
I am looking for the Ruby-est way to solve a problem. I have code
I am looking for a nice code solution for the following problem. I have
Summary: I have a list of policy numbers I'm looping through in Column A
I'm looking for the generally accepted/best solution to this problem. Problem I have a
Thanks for looking on this problem. I have a page that is totally valid
I am looking for a simple answer for this problem... I have a UITextView
I' ve got a problem with Haskell. I have text file looking like this:
I have problem with http://abfoodpolicy.com/ . In IE 8 and 9 the right sidebar

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.