c# - How to use math operators with strings? -


this question has answer here:

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

Popular posts from this blog

python - Healpy: From Data to Healpix map -

c - Bitwise operation with (signed) enum value -

xslt - Unnest parent nodes by child node -