Click here to Skip to main content
16,005,080 members
Home / Discussions / C#
   

C#

 
AnswerRe: Threading Conversion Pin
led mike8-Nov-06 5:30
led mike8-Nov-06 5:30 
GeneralRe: Threading Conversion Pin
eatwork8-Nov-06 12:24
eatwork8-Nov-06 12:24 
QuestionI want a prettier application Pin
lsugirljte8-Nov-06 3:43
lsugirljte8-Nov-06 3:43 
AnswerRe: I want a prettier application Pin
Pete O'Hanlon8-Nov-06 4:19
mvePete O'Hanlon8-Nov-06 4:19 
AnswerRe: I want a prettier application Pin
Just me at will_george...something8-Nov-06 4:27
Just me at will_george...something8-Nov-06 4:27 
QuestionSemantics of Object.Equals(object) Pin
Goebel8-Nov-06 3:03
Goebel8-Nov-06 3:03 
AnswerRe: Semantics of Object.Equals(object) Pin
led mike8-Nov-06 5:24
led mike8-Nov-06 5:24 
AnswerRe: Semantics of Object.Equals(object) Pin
Scott Dorman8-Nov-06 7:16
professionalScott Dorman8-Nov-06 7:16 
The members are native data (value) types, so ((this.a == test.a) && (this.b == test.b)) will properly evaluate to a boolean expression. The runtime already knows how to test for integer equality, so the logic you present should work just fine.

A few things to keep in mind, the as operator will return null if obj is not an object of type Tester (I assume you meant Tester and not Test as you have in your example) so you should test that test is not null before using it. You really should test to make sure obj isn't null as well.

The modified method would look like this:
C#
public override bool Equals(object obj)
{
   if (obj == null)
   {
      return false;
   }
 
   Tester tester = obj as Tester;
 
   if (tester == null)
   {
      return false;
   }
 
   if ((this.a == tester.a) && (this.b == tester.b))
   {
      return true;
   }
   else
   {
      return false;
   }
}
Also, you should also be overriding the GetHashCode(), equality, and inequality operators.

Finally, you should consider deriving your class from IEquatable<T> if you are using .NET 2.0/3.0 and implement the following functions:

public bool Equals(Tester obj)

and

public static bool Equals(Tester t1, Tester t2)

although the static method is optional but convenient


-----------------------------
In just two days, tomorrow will be yesterday.

GeneralRe: Semantics of Object.Equals(object) Pin
Goebel22-Nov-06 4:49
Goebel22-Nov-06 4:49 
Questionpopulate word document Pin
mian ghous8-Nov-06 2:48
mian ghous8-Nov-06 2:48 
AnswerRe: Creating a generic item dynamically Pin
Stefan Troschuetz8-Nov-06 4:07
Stefan Troschuetz8-Nov-06 4:07 
GeneralRe: Creating a generic item dynamically Pin
Ista8-Nov-06 11:52
Ista8-Nov-06 11:52 
GeneralRe: Creating a generic item dynamically Pin
mian ghous10-Nov-06 0:06
mian ghous10-Nov-06 0:06 
Questionmp3 tags. Pin
ToddHileHoffer8-Nov-06 2:09
ToddHileHoffer8-Nov-06 2:09 
AnswerRe: mp3 tags. Pin
Ista8-Nov-06 11:55
Ista8-Nov-06 11:55 
QuestionNewbie: How to detect if an item in a DB record is null (mysql)... Pin
Phillip Hodges8-Nov-06 2:06
Phillip Hodges8-Nov-06 2:06 
AnswerRe: Newbie: How to detect if an item in a DB record is null (mysql)... Pin
_mubashir8-Nov-06 2:26
_mubashir8-Nov-06 2:26 
GeneralRe: Newbie: How to detect if an item in a DB record is null (mysql)... Pin
Phillip Hodges8-Nov-06 2:32
Phillip Hodges8-Nov-06 2:32 
GeneralRe: Newbie: How to detect if an item in a DB record is null (mysql)... Pin
Guffa8-Nov-06 2:41
Guffa8-Nov-06 2:41 
GeneralRe: Newbie: How to detect if an item in a DB record is null (mysql)... Pin
Phillip Hodges8-Nov-06 3:03
Phillip Hodges8-Nov-06 3:03 
GeneralRe: Newbie: How to detect if an item in a DB record is null (mysql)... Pin
Guffa8-Nov-06 22:50
Guffa8-Nov-06 22:50 
AnswerRe: Newbie: How to detect if an item in a DB record is null (mysql)... Pin
ednrgc8-Nov-06 2:47
ednrgc8-Nov-06 2:47 
AnswerRe: Newbie: How to detect if an item in a DB record is null (mysql)... Pin
V.8-Nov-06 3:01
professionalV.8-Nov-06 3:01 
Questioncreating tab page control in project property window Pin
sakthi s8-Nov-06 1:58
sakthi s8-Nov-06 1:58 
AnswerRe: creating tab page control in project property window Pin
quiteSmart8-Nov-06 2:11
quiteSmart8-Nov-06 2:11 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.