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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T12:32:32+00:00 2026-06-14T12:32:32+00:00

I filled some ObservableCollection<Employe> collection: // Program.Data.Employees – it is ObservableCollection<Employe>. Program.Data.Employees.Add(new Employe() {

  • 0

I filled some ObservableCollection<Employe> collection:

// Program.Data.Employees - it is ObservableCollection<Employe>.
Program.Data.Employees.Add(new Employe() { Name="Roman", Patronymic="Petrovich", Surname="Ivanov" });
Program.Data.Employees.Add(new Employe() { Name = "Oleg", Patronymic = "Vladimirovich", Surname = "Trofimov" });
Program.Data.Employees.Add(new Employe() { Name = "Anton", Patronymic = "Igorevich", Surname = "Kuznetcov" });

In other place of my code I try to remove some item from this collection:

// Program.Data.Employees - it is ObservableCollection<Employe>.
Employe x = Program.Data.Employees.First(n => n.Guid == emp.Guid); // x is not null.
Int32 index = Program.Data.Employees.IndexOf(x); // I got -1. Why?
Boolean result = Program.Data.Employees.Remove(x); // I got 'false', and item is not removed. Why?
// But this works fine:
Program.Data.Employees.Clear();

I can clear collection, but I can’t remove necessary item. Why it happens?

UPD: Equals method of my Employe class

public bool Equals(Employe other) {
    return
    other.Guid == this.Guid &&
    String.Equals(other.Name, this.Name, StringComparison.CurrentCultureIgnoreCase) &&
    String.Equals(other.Patronymic == this.Patronymic, StringComparison.CurrentCultureIgnoreCase) &&
    String.Equals(other.Surname == this.Surname, StringComparison.CurrentCultureIgnoreCase) &&
    other.Sex == this.Sex &&
    String.Equals(other.Post == this.Post, StringComparison.CurrentCultureIgnoreCase);
}
  • 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-14T12:32:33+00:00Added an answer on June 14, 2026 at 12:32 pm

    I tried the following code to reproduce your error:

    class Employee
    {
      public string Name { get; set; }
      public Guid Guid { get; set; }
    }
    
    // ...
    ObservableCollection<Employee> employees = new ObservableCollection<Employee>();
    var guid1 = Guid.NewGuid();
    employees.Add(new Employee { Name = "Roman", Guid = guid1 });
    employees.Add(new Employee { Name = "Oleg", Guid = Guid.NewGuid() });
    
    var x = employees.First(e => e.Guid == guid1);
    var index = employees.IndexOf(x); // index = 0, as expected
    var result = employees.Remove(x); // result = true, as expected
    

    It worked as expected. I would suggest, you set a breakpont at var x = ... and check, if

    • The collection really contains the item you’re looking
    • If First() really returns that item

    Then go to the next line and check, if index is returned correctly. And finally check again, if result is really false.

    I see several possible causes of your code failing:

    • You didn’t post the full code and something happens between x=Program.Data.Employees.First() and Program.Data.Employees.IndexOf()
    • You use multithreaded code (which also results in “something happening” between the two statements). In this case, you need to synchronize the access to the collection
    • You don’t use a ObservableCollection directly but some derived class instead which is constructed by your data layer (such as DataServiceCollection, but this one should work fine too). In this case, check the actual type of your collection in the debugger

    Another typical cause of errors with collection would be, if you try to remove items while iterating over the collection (i.e. inside a foreachloop): but in this case an exception should be thrown (and IndexOf should work fine), so this would only apply if you use some derived class which implements non-standard behaviour.

    EDIT (in return to you posting your Equal method)

    Your Equal method has a serious error in it:

    String.Equals(other.Patronymic == this.Patronymic, StringComparison.CurrentCultureIgnoreCase)
    ... // applies also for following comparisons
    

    should be

    String.Equals(other.Patronymic, this.Patronymic, StringComparison.CurrentCultureIgnoreCase)
    ...
    

    Also, if you’re using a Guid, consider only comparing the GUIDs, since this usually means ‘unique identifier’, so it should be enough to identify some entity.

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

Sidebar

Related Questions

If I have a DBGrid in a form filled with some data and I
I have a SqlServer database that I've manually filled with some test data. Now
I have a grid filled with some data in my silverlight4 app. I want
I want to have my excel file filled with some data which I get
Good day, i have mongodb database filled with some data, i ensured that data
Lets say i have an Array collection, filled with some elements. If i say
I have a working UITableView filled with some options for my app, and i
How to draw multiple circles horizontally in android, with some filled color. And I
Alright, I have a really basic QStandardItemModel , filled with some numbers. I managed
i have this letter where in some parts will be filled-up by the user.

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.