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

  • Home
  • SEARCH
  • 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 7945975
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T01:00:56+00:00 2026-06-04T01:00:56+00:00

I have a list with Customer objects and I’m trying to search for a

  • 0

I have a list with Customer objects and I’m trying to search for a name in each object. In the Customer object there is a properties, ContactData, that return a Contact object. And inside the Contact object I have a method that returns a string of a name. It is that name I’m trying to compare with, but it’s not working properly, because I get a hit every time, despite I search for a name that don’t exist in any of the Customer object. The code I’m using:

foreach (Customer name in m_customers)
{
      if (name.ContactData.FullName == "Anna") 
      {
          MessageBox.Show(string.Format("Yes"), "Test!", MessageBoxButtons.OK, MessageBoxIcon.Information); // Just for testing  
      }
}

I have also tested to use a simple for loop, but I get the same result. I’m not sure I’m doing the right thing and would preciate some help! Thanks!

  • 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-04T01:00:58+00:00Added an answer on June 4, 2026 at 1:00 am

    Try this, it might be that the ‘FullName’ is somehow being set to “Anna” for all customers somewhere in your code, or in the database, or in the stored proc…

    foreach (Customer name in m_customers) 
    { 
        if(name.ContactData != null) System.Diagnostics.Debug.WriteLine(name.ContactData.FullName);
    
        if (name.ContactData.FullName == "Anna")  
        { 
            MessageBox.Show(string.Format("Yes"), "Test!", MessageBoxButtons.OK, MessageBoxIcon.Information); // Just for testing   
        } 
    } 
    

    If that’s the case, do a global search for the keyword ‘Anna’ and see what pops up.

    The other possibility is that you’re not creating a new ContactData object with each Customer and simply reusing a variable. This might be updating all Customers with the SAME ContactData object because a pointer is being used. Instead, with each Customer, create a brand new ContactData object instead.

    If these two possibilities don’t help, you’ll have to post more code to troubleshoot.

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

Sidebar

Related Questions

I have a list of objects in an asp.net page. Each object represents a
I have a list of Customer objects that I need to have selectable from
I have a list of Customers. Each customer has an address and some customers
I have an app that has a list of items. My customer prefers to
I have a List of customers that I'm trying to bind to a DataGridView.
I have a heterogeneous List that can contain any arbitrary type of object. I
I'm using linq to pull back an object (i.e. customer) that might have a
I have a method which should return a list of anonymous objects with a
I have a collection called navigationList . This list holds customer objects. A customer
I have a list of this object: public class Customer { public int Id

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.