Skip to content

Instantly share code, notes, and snippets.

@dgg
Last active December 12, 2016 14:00
Show Gist options
  • Select an option

  • Save dgg/f9cd5556cf4684f5f750 to your computer and use it in GitHub Desktop.

Select an option

Save dgg/f9cd5556cf4684f5f750 to your computer and use it in GitHub Desktop.
equality-implicit-nastysurprises
Money? fiver = 5m.Gbp();
MonetaryQuantity anotherFiver = (MonetaryQuantity)5m.Gbp();
Assert.That(EqualityComparer<Money?>.Default.Equals(fiver, anotherFiver), Is.True);
Assert.That(Nullable.Equals(fiver, anotherFiver), Is.True);
Assert.That(fiver.Equals(anotherFiver), Is.True); // fail!!!
Money? nullable = new Money(1, “XXX”);
// from Nullable<Money>
MonetaryQuantity succint = nullable;
// from Money thanks to nullable implicit magic
MonetaryQuantity evenMoreSuccint = 1m.Xxx();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment