Skip to content

Instantly share code, notes, and snippets.

@dcomartin
Last active January 26, 2024 14:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dcomartin/5fba287d12f20f48b65294f9bcc716e9 to your computer and use it in GitHub Desktop.
Save dcomartin/5fba287d12f20f48b65294f9bcc716e9 to your computer and use it in GitHub Desktop.
public record Quantity
{
private int Value { get; }
public Quantity(int value)
{
if (value <= 0)
{
throw new InvalidOperationException("Quantity must be greater than zero.");
}
Value = value;
}
public static implicit operator int(Quantity quantity) => quantity.Value;
}
@jud3ies
Copy link

jud3ies commented Dec 11, 2023

Shouldn't the condition on line 7 be value <= 0 instead of value >= 0?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment