[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 222
  • Last Modified:

Collection.Add doesn't give me the expected result

Can't figure this one out.

I'm buildning a Collection inhertid from CollectionBase.

It seems that this code part doesn't work, when I use the collection in my WebForm:

----

public int Add(Company company)
{
  return this.InnerList.Add(company);
}

----

No matter what the Collection.Count remains zero - what's wrong??
0
korona5
Asked:
korona5
  • 2
1 Solution
 
korona5Author Commented:
Sorry made a mistake before...

The problem lies in Collection.Contains here:

_Company = new Company(1);
_CompanyCollection.Add(_Company);

_Company = new Company(1);
_CompanyCollection.Contains(_Company) <--- this one returns false - I think it should return true - but why not???

---

from collection:

            public bool Contains(BLL.Classes.Company company)
            {
                  return this.InnerList.Contains(company);
            }
0
 
RomanPetrenkoCommented:
You have to implement IsEqual method in your company class
0
 
korona5Author Commented:
Thank you so much! I'm running late on this project :-)

I did this:

public override bool Equals(object obj)
{
      Company _Company = (obj as Company);

      if (_Company == null)
            return false;

      return this.CompanyId.Equals(_Company.CompanyId);
}

And it works like a charm.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now