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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T23:25:05+00:00 2026-05-20T23:25:05+00:00

Hi I just ran into a sync problem, and have replicated it in this

  • 0

Hi I just ran into a sync problem, and have replicated it in this small example.

class MyClass
    {
        public int Number { get; set; }
    }

static void Main(string[] args)
        {
            var list = new ObservableCollection<MyClass>
                           {
                               new MyClass() {Number = 1},
                               new MyClass() {Number = 2},
                               new MyClass() {Number = 3}
                           };

            var count = from i in list where i.Number == 1 select i;
            Console.WriteLine("Found {0}", count.Count());

            list[2].Number = 1;
            Console.WriteLine("Found {0}", count.Count());
        }

This will output

Found 1
Found 2

This is not what I expected, would have guessed it would return 1 both times.
It there anyway to avoid this action and still use a observable collection?

I’m trying to implement a method to reorder, but this makes it hard to select the correct item.

UPDATE

An easy solution would of cource be to modify it like this

int found = count.Count();
            Console.WriteLine("Found {0}", found);

            list[2].Number = 1;
            Console.WriteLine("Found {0}", found);
  • 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-20T23:25:05+00:00Added an answer on May 20, 2026 at 11:25 pm

    This is due to the lazy evaluation of your LINQ query and has nothing to do with the ObservableCollection. If you change your LINQ query to the following line:

    (from i in list where i.Number == 1 select i).ToList();
    

    you will see the behavior you expect.

    The ToList() addition makes sure your LINQ query is evaluated at that moment. Otherwise, it is evaluated only when necessary. Because you call Count() twice, the query is evaluated twice but on different data.

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

Sidebar

Related Questions

I just ran into a problem involving Expressions . In my class<T> have a
We have a website and we just ran into a problem when trying to
I just ran into to strange problem, I have a custom tableview cell with
I have a mapView with custom annotations and just ran into a problem on
Just ran into this: #include <iostream> using namespace std; int main(int argc, char** argv)
Just ran into this very frustrating problem when trying to add a new view,
I just ran into this issue while making a GET request to a node.js
I just ran into a problem with the version of JAX-WS in JDK 1.6.0
I just ran into a problem.. I'm trying to build a website at the
I'm new in python, and just ran into this statement data = dict( (k,

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.