For those coming late to this please refer below for the more acceptable answer which is hidding in comments from @Jeppe Stig Nielsen.
The op has asked specifically about overriding operator == , however, I believe this is an important piece of information when overriding the == operator and believe the correct answer for future reference should be:-
Console.WriteLine((object)someObject == null);
Using the accepted answer and implementing both == and Equals in your object, you will continue to get same error. Best to compare to null at the lowest level object, that way you are comparing 'object' to null and all ambiguity is removed from the comparison.
Here is the reason and resolution as per implemented in MSDN: Guidelines for Overriding Equals() and Operator ==
Consider the following, refer the comments in the Equals implementation:-
class SomeClass
{
string value;
public SomeClass(string _Value)
{
value = _Value;
}
static public bool operator ==(SomeClass C1, SomeClass C2)
{
return C1.value == C2.value;
}
public override bool Equals(SomeClass C1)
{
// causes error due to unsure which operator == to use the SomeClass == or the object ==
// Actual error: Operator '==' is ambiguous on operands of type 'SomeClass' and '<null>'
if (C1 == null)
return false;
// Give same error as above
if (C1 == default(SomeClass))
return false;
// Removes ambiguity and compares using base objects == to null
if ((object)C1 == null)
return false;
return value == C1.value;
}
}