Operator overloading in C#
<pre><code>        [Serializable]
        public class ComplexArray
        {
            #region Attributes

            /// &lt;summary&gt;
            /// Array Size
            /// &lt;/summary&gt;
            protected int m_iSize;

            /// &lt;summary&gt;
            /// Real part of the data
            /// &lt;/summary&gt;
            protected double[] m_dReal;

            /// &lt;summary&gt;
            /// Imaginary part of the data
            /// &lt;/summary&gt;
            protected double[] m_dImag;

            #region Construction

            /// &lt;summary&gt;
            /// Default constructor
            /// &lt;/summary&gt;
            public ComplexArray()
            {
            }


            public override bool Equals(object o)
            {
                if (this == (ComplexArray)o)
                    return true;
                else
                    return false;
            }



            public static bool operator ==(ComplexArray src1, ComplexArray src2)
            {
                if (src1.m_iSize != src2.m_iSize)
                    return false;

                for (int ii = 0; ii &lt; src1.m_iSize; ii++)
                {
                    if (src1.Real[ii] != src2.Real[ii])
                        return false;
                    if (src1.Imag[ii] != src2.Imag[ii])
                        return false;
                }

                return true;
            }

            public static bool operator !=(ComplexArray src1, ComplexArray src2)
            {

                if (src1 == src2)
                    return false;
                else
                    return true;
            }

    }
</code></pre>

<p>I have a created a class called complex array and intention of this class is to save real and imaginary numbers and different operators have been overloaded like +,*,!=,==</p>

<p>Assume some function returns the instance of this class.</p>

<pre><code>ComplexArray array = GetValue();
</code></pre>

<p>I want to check whether the reference is valid or not...</p>

<pre><code>    if(array != null)
    {
      //proceed further....
    }
</code></pre>

<p>Issue : When the value is checked against null value, the exception occurs, because internally != overloaded function calls the ==.</p>

<p>How to avoid this kind of situation in operator overloading? Or how to make the operator != or == to check for the null value and return the correct values(true or false)</p>
