c# - How to use math operators with strings? -
this question has answer here:
- how can convert string int? 24 answers
i need display number on label when user input between >=0 , <= 1. user input string , need numbers between decimal or double. can't compare 2 did because operators can't compare string , decimal, double, or int.
private void voltagetextbox_textchanged(object sender, eventargs e) { var rtpower = powertextbox.text; powertextbox.charactercasing = charactercasing.upper; if (rtpower >= 0 && <= 1) { displaylabel4.text = "1"; } }
error: operator '>=' cannot applied operands of type 'string' , 'int'
error: operator '<=' cannot applied operands of type 'string' , 'int'
how can make if statement work? have keep string, display in label, convert label integer re-display it? know can make work, far complicated. need easier way this.
int rtpower = int32.parse(powertextbox.text);
or decimal values
decimal rtpower = decimal.parse(powertextbox.text);
you need convert value string int.
also, assume new c# - advice avoid using var , explicitly declare variables. make things clear , easier learn , understand.
Comments
Post a Comment