Re: Compare two instance of a class
From: richlm (rich_lm_at_h0tmai1.com)
Date: 08/02/04
- Next message: Kai Bøhli: "Jon Skeet - Encoding and labelprinters - thanks for your solution"
- Previous message: Eifel-benz: "RE: Connection to a MS Access database"
- In reply to: bengamin: "Compare two instance of a class"
- Next in thread: Razzie: "Re: Compare two instance of a class"
- Reply: Razzie: "Re: Compare two instance of a class"
- Messages sorted by: [ date ] [ thread ]
Date: Mon, 2 Aug 2004 11:23:54 +0200
Recommended practice is that operator "==" and method
"Object.Equals(object)" should behave the same.
If you override Equal you should also override GetHashCode.
You need to bear in mind whether or not you will ever need to compare 2
references (which is the default behaviour) i.e. that refer to the same
instance.
In most cases I think it is better to implement a specific method to compare
reference type instances - value comparison is often a business/application
specific function, and it may be misleading to some developers if you
override default language functionality.
Here's a useful article on MSDN:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpgenref/html/cpconimplementingequalsoperator.asp
Richard.
"bengamin" <saixh@langchao.com> wrote in message
news:eayVLUDeEHA.3476@tk2msftngp13.phx.gbl...
> Hi,
>
> I have a C# class and two instance of the class;
>
> the class have some property.
>
> I want to compare the property value of the two instance
>
> How should i do? override == ? use delegate ?
>
> I am sorry ,my english was poor.
>
>
>
- Next message: Kai Bøhli: "Jon Skeet - Encoding and labelprinters - thanks for your solution"
- Previous message: Eifel-benz: "RE: Connection to a MS Access database"
- In reply to: bengamin: "Compare two instance of a class"
- Next in thread: Razzie: "Re: Compare two instance of a class"
- Reply: Razzie: "Re: Compare two instance of a class"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|