-
-
Save dcomartin/5fba287d12f20f48b65294f9bcc716e9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Shouldn't the condition on line 7 be
value <= 0
instead ofvalue >= 0
?