Franck Diastein wrote:
> Hi, I have create a TypeSafe collection with CollectionBase, but I don't
> know how to update an object... Let's say I have an Animal class with
> Animals collection.
> Animal has a property named Number that's unique in entire collection...
>
> I would like to do something aka in my form:
>
> private void UpdateAnimal(Animal UpdatedAnimal){
>
> int i = UpdatedAnimal.Number
> m_Animals.Update(UpdatedAnimal,i)
>
> }
>
> What is the best way to implement this ? Am I taking the right approach ?
BEST way is to override Equals in Animal and implement it so it
compares the Number properties of the current animal and the one passed in.
With that, you can then do:
m_Animals[m_Animals.IndexOf(UpdatedAnimal)].Number = newValue;
IndexOf, Contains, they work all with the Equals method of the object
contained in the collection.
Frans
--
------------------------------------------------------------------------
Get LLBLGen Pro, productive O/R mapping for .NET:
http://www.llblgen.com
My .NET blog:
http://weblogs.asp.net/fbouma
Microsoft MVP (C#)
------------------------------------------------------------------------