• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 225
  • 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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

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