Click here to Skip to main content
15,900,616 members
Home / Discussions / C#
   

C#

 
QuestionRe: windows safe mode Pin
shabonaa10-Jan-06 17:22
shabonaa10-Jan-06 17:22 
AnswerRe: windows safe mode Pin
Sebastian Schneider10-Jan-06 22:44
Sebastian Schneider10-Jan-06 22:44 
AnswerRe: windows Standby Pin
shabonaa11-Jan-06 2:05
shabonaa11-Jan-06 2:05 
Questiondoes anybody have queen mc_klaski code? Pin
m.rastgar10-Jan-06 9:12
m.rastgar10-Jan-06 9:12 
Questionhow to make forms same size Pin
zhujp9810-Jan-06 9:04
zhujp9810-Jan-06 9:04 
AnswerRe: how to make forms same size Pin
Curtis Schlak.10-Jan-06 9:19
Curtis Schlak.10-Jan-06 9:19 
AnswerRe: how to make forms same size Pin
shabonaa10-Jan-06 9:26
shabonaa10-Jan-06 9:26 
QuestionSerious fault in overloading operator== in C# Pin
Jesper196610-Jan-06 9:02
Jesper196610-Jan-06 9:02 
I overload operator== in a class, say, MyClass, like this

public static bool operator==(MyClass lhs, MyClass rhs) {<br />
   return lhs.someValue == rhs.someValue;<br />
}


Which will fail if either lhs or rhs is null. Fix

public static bool operator==(MyClass lhs, MyClass rhs) {<br />
   try {<br />
      return lhs.someValue == rhs.someValue;<br />
   } catch (Exception) {<br />
      return false;<br />
   }<br />
}


But this will result in the following code not working
void MyFunction(MyClass anInstance) {<br />
   if (anInstance == null) {<br />
      // Will not be called do to catch block above ...<br />
   }<br />
}


Fix
public static bool operator==(MyClass lhs, MyClass rhs) {<br />
   if (lhs == null && rhs == null) {<br />
      return true;<br />
   }<br />
<br />
   try {<br />
      return lhs.someValue == rhs.someValue;<br />
   } catch (Exception) {<br />
      return false;<br />
   }<br />
}

But this causes a stack overflow since the check on "lhs == null" calls operator== again ...

Help someone pls Wink | ;-)


-- modified at 15:05 Tuesday 10th January, 2006
AnswerRe: Serious fault in overloading operator== in C# Pin
User 665810-Jan-06 9:10
User 665810-Jan-06 9:10 
GeneralRe: Serious fault in overloading operator== in C# Pin
Jesper196610-Jan-06 9:16
Jesper196610-Jan-06 9:16 
GeneralRe: Serious fault in overloading operator== in C# Pin
Curtis Schlak.10-Jan-06 9:18
Curtis Schlak.10-Jan-06 9:18 
AnswerRe: Serious fault in overloading operator== in C# Pin
Curtis Schlak.10-Jan-06 9:17
Curtis Schlak.10-Jan-06 9:17 
GeneralRe: Serious fault in overloading operator== in C# Pin
Jesper196610-Jan-06 9:29
Jesper196610-Jan-06 9:29 
GeneralRe: Serious fault in overloading operator== in C# Pin
User 665810-Jan-06 9:35
User 665810-Jan-06 9:35 
GeneralRe: Serious fault in overloading operator== in C# Pin
Curtis Schlak.10-Jan-06 9:53
Curtis Schlak.10-Jan-06 9:53 
AnswerRe: Serious fault in overloading operator== in C# Pin
Daniel Grunwald10-Jan-06 9:38
Daniel Grunwald10-Jan-06 9:38 
GeneralRe: Serious fault in overloading operator== in C# Pin
Jesper196610-Jan-06 9:44
Jesper196610-Jan-06 9:44 
GeneralRe: Serious fault in overloading operator== in C# Pin
Daniel Grunwald11-Jan-06 3:28
Daniel Grunwald11-Jan-06 3:28 
AnswerRe: Serious fault in overloading operator== in C# Pin
leppie10-Jan-06 18:59
leppie10-Jan-06 18:59 
QuestionCreating mailbox from web service Pin
VPR10-Jan-06 8:27
VPR10-Jan-06 8:27 
AnswerRe: Creating mailbox from web service Pin
Curtis Schlak.10-Jan-06 9:08
Curtis Schlak.10-Jan-06 9:08 
QuestionShowing check mark in menu item Pin
smurfy3410-Jan-06 8:16
smurfy3410-Jan-06 8:16 
AnswerRe: Showing check mark in menu item Pin
Curtis Schlak.10-Jan-06 8:41
Curtis Schlak.10-Jan-06 8:41 
Questionlabel color in form Pin
zhujp9810-Jan-06 8:09
zhujp9810-Jan-06 8:09 
AnswerRe: label color in form Pin
Curtis Schlak.10-Jan-06 8:34
Curtis Schlak.10-Jan-06 8:34 

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.