DotNetNewsgroup.com  
web access to complete list of Microsoft.NET newsgroups
   home   |   control panel login   |   archive  |  
 
  carried group
academic
adonet
aspnet
aspnet.announcements
aspnet.buildingcontrols
aspnet.caching
aspnet.datagridcontrol
aspnet.mobile
aspnet.security
aspnet.webcontrols
aspnet.webservices
assignment_manager
datatools
dotnet.distributed_apps
dotnet.general
dotnet.myservices
dotnet.nternationalization
dotnet.scripting
dotnet.security
dotnet.vjsharp
dotnet.vsa
dotnet.xml
dotnetfaqs
framework
framework.clr
framework.compactframework
framework.component_services
framework.controls
framework.databinding
framework.drawing
framework.enhancements
framework.interop
framework.odbcnet
framework.performance
framework.remoting
framework.sdk
framework.setup
framework.webservices
framework.windowsforms
framework.wmi
frwk.windowsforms.designtime
lang.csharp
lang.jscript
lang.vb
lang.vb.controls
lang.vb.data
lang.vb.upgrade
lang.vc
lang.vc.libraries
  
 
start date: Fri, 17 Aug 2007 16:12:04 -0400,    posted on: microsoft.public.dotnet.framework        back       

Thread Index
  1    Mario Vargas
          2    Scott M. am


Overriding Equals   
Hello all,

I am faced with a dilemma with a class I am working on. I am overriding the 
Equals() method to be able to make comparisons with objects of the same 
type, but this class has a member field that contains a collection. My 
problem is, the two objects I am comparing are exactly the same but the 
collections in each object are different. Is it a good idea to check 
equality of member fields that are collections?

For example: class MyClass has two member fields: Name and Jobs. Jobs is a 
JobCollection of Job objects. Both MyClass and JobCollection override 
Equals(). I have a instance B of MyClass that contains 4 Jobs and in an 
Array of MyClass objects, I have element C that contains the same name as B 
but only consists of 3 Jobs. The Jobs are unsynchronized because when B 
changed from 3 to 4, there was no way to notify the Array of MyClass objects 
that B and C are the same and the new Job added to B had to be added to C as 
well.

Thanks for your input! I know that for instance a collection such as 
StringCollection doesn't override the Equals() method.

Mario
Date:Fri, 17 Aug 2007 16:12:04 -0400   Author:  

Re: Overriding Equals   
I would consider creating a custom collection class and overriding the 
Equals() method on that.  Then use that class from within your new class.


"Mario Vargas"  wrote in message 
news:%23B48jrQ4HHA.5216@TK2MSFTNGP05.phx.gbl...

> Hello all,
>
> I am faced with a dilemma with a class I am working on. I am overriding 
> the Equals() method to be able to make comparisons with objects of the 
> same type, but this class has a member field that contains a collection. 
> My problem is, the two objects I am comparing are exactly the same but the 
> collections in each object are different. Is it a good idea to check 
> equality of member fields that are collections?
>
> For example: class MyClass has two member fields: Name and Jobs. Jobs is a 
> JobCollection of Job objects. Both MyClass and JobCollection override 
> Equals(). I have a instance B of MyClass that contains 4 Jobs and in an 
> Array of MyClass objects, I have element C that contains the same name as 
> B but only consists of 3 Jobs. The Jobs are unsynchronized because when B 
> changed from 3 to 4, there was no way to notify the Array of MyClass 
> objects that B and C are the same and the new Job added to B had to be 
> added to C as well.
>
> Thanks for your input! I know that for instance a collection such as 
> StringCollection doesn't override the Equals() method.
>
> Mario
>
> 
Date:Fri, 17 Aug 2007 16:49:31 -0400   Author:  

Google
 
Web dotnetnewsgroup.com


COPYRIGHT ?2005, EUROFRONT WORLDWIDE LTD., ALL RIGHT RESERVE  |   Contact us