Skip to content

Text Prompt validation with another variable #633

Answered by nils-a
kevball2 asked this question in Q&A
Discussion options

You must be logged in to vote

I'm guessing your question is related to the error your code produces:

CS0150: A constant value is expected

The reason for this is not really dependent on spectre.console but rather on the C# specs for the switch.
You would need to change your switch to a var pattern like this:

return newWage switch
{
  var x when x < oldWage => ValidationResult.Error("[yellow]New wage cannot be less than current wage[/]"),
  _ => ValidationResult.Success(),
};

alternatively you can always use an if - which in this case would (in my opinion) be much, much clearer.

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@kevball2
Comment options

Answer selected by nils-a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants