c# - Why string type is not converting to int type? -
i want add 2 numbers. getting values button in textbox. succeeded in splitting string substrings , store values of these substrings in variables. not able convert string type integer type. results in concatenation not in addtion. note : using mvc perform task. , in model value1 , value2 string type in model here code snippet:
if (button == "1"){ if (model.textbox == "" || model.textbox == null || model.textbox.tolower().contains("please enter value")){ model.textbox = "1"; } else { model.textbox += "1"; } } if (button == "2") { if (model.textbox == "" && model.textbox == null) { model.textbox = "2"; } else { model.textbox += "2"; } if (button == "+") { if (model.textbox == "" && model.textbox == null){ model.errormsg = "please enter number "; } else { model.textbox += "+"; } if (button == "=") { if (model.textbox.contains("+")) { model.value1 = (model.textbox.split('+'))[0]; int value1 = int.parse(model.value1); model.value2 = (model.textbox.split('+'))[1]; int value2 = int.parse(model.value2); model.textbox = model.value1 + model.value2; } return view(model);
if got correctly need is:
model.textbox = (value1 + value2).tostring();
Comments
Post a Comment