Google Groups Home
Help | Sign in
Null with Custom Types
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  2 messages - Collapse all
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Steve Berwick  
View profile
 More options Aug 26 2008, 1:47 am
From: Steve Berwick <steveberw...@gmail.com>
Date: Mon, 25 Aug 2008 07:47:17 -0700 (PDT)
Local: Tues, Aug 26 2008 1:47 am
Subject: Null with Custom Types
I have created my own class called Transaction.

I have overloaded the Equals and NotEquals functions so that I can
simply use == or != to compare 'Transactions'.

The problem I am faced with is that I cannot figure out how to account
for Null transactions.

If inside the Equals function I say:

public override bool Equals(Object obj)
{
   Transaction x = (Transaction) obj;

   if (this == null || x == null)
      return false;         // will never reach here, because the
above will continue to loop forever until i get a stack overflow
because it will recursively call Equals a billion times.

   // my normal comparison checks

}

If I try to look at a member variable to validate  (x.AcquirerRT ==
null)   i get an 'object not instantiated' error message.  Which makes
sense.

I understand what is going on, but I don't know how to get around it.
Any time I try to say "== null", I get a stack overflow.  So then how
can I check for null?


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Cerebrus  
View profile
 More options Aug 26 2008, 9:44 pm
From: Cerebrus <zorg...@sify.com>
Date: Tue, 26 Aug 2008 03:44:45 -0700 (PDT)
Local: Tues, Aug 26 2008 9:44 pm
Subject: Re: Null with Custom Types
Use the ReferenceEquals method instead of Equals.

For guidelines about this particular issue, see:

<http://msdn.microsoft.com/en-us/library/ms173147(VS.80).aspx>

On Aug 25, 7:47 pm, Steve Berwick <steveberw...@gmail.com> wrote:


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2009 Google