using System.Collections.Generic;
public string Street { get; set; }
public string City { get; set; }
public string State { get; set; }
public string Zip { get; set; }
public string Name { get; set; }
public int Age { get; set; }
public float HeightInInches { get; set; }
public Dictionary<string, Address> Addresses { get; set; }
public bool IsNull { get; }
public NullTest(T value) => IsNull = value == null;
public class NullTestCorrect<T> where T : BaseObj
public bool IsNull { get; }
public NullTestCorrect(T value) => IsNull = value == null;
public static bool operator ==(BaseObj lhs, BaseObj rhs)
return CompareBaseObjects(lhs, rhs);
public static bool operator !=(BaseObj lhs, BaseObj rhs)
public override bool Equals(object other)
BaseObj otherAsObject = other as BaseObj;
if (otherAsObject == null && other != null && !(other is BaseObj))
return CompareBaseObjects(this, otherAsObject);
static bool CompareBaseObjects(BaseObj lhs, BaseObj rhs)
bool lhsNull = ((object)lhs) == null;
bool rhsNull = ((object)rhs) == null;
if (rhsNull && lhsNull) return true;
Console.WriteLine(nameof(CompareBaseObjects));
public override int GetHashCode()
Console.WriteLine(nameof(GetHashCode));
public class MyObj : BaseObj
public static bool NullTestMethod<T>(T value) => value == null;
public static bool NullTestMethodConstrained<T>(T value) where T : BaseObj => value == null;
public static void Main()
Console.WriteLine("Null Test:");
Console.WriteLine(new NullTest<MyObj>(new MyObj()).IsNull);
Console.WriteLine("Null Test Correct:");
Console.WriteLine(new NullTestCorrect<MyObj>(new MyObj()).IsNull);
Console.WriteLine("Null Test Method:");
Console.WriteLine(NullTestMethod(new MyObj()));
Console.WriteLine("Null Test Correct Method:");
Console.WriteLine(NullTestMethodConstrained(new MyObj()));