Home > 2. Windows Programming, Managed Code > A trick of operator== with NULL value in C#

A trick of operator== with NULL value in C#


public static bool operator ==(Buddy b1, Buddy b2)
{
 if ((object)b2 == null && (object)b1 == null)
 {
  return true;
 }
 else if ((object)b2 != null && (object)b1 != null)
 {
  return (b1.Nick == b2.Nick);
 }
 else
  return false;
}

Advertisements
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: