how to take integer input in c#
-
For console programing you hava to use using System.Console.; & then use ch = System.Console.Read(); //return charater Or str = System.Console.ReadLine(); //return string Divyang Mithaiwala with Best Regards
-
For console programing you hava to use using System.Console.; & then use ch = System.Console.Read(); //return charater Or str = System.Console.ReadLine(); //return string Divyang Mithaiwala with Best Regards
-
I want to take integer value and not char or string. Actually System.Console.Read() reads kay pressed and not int. :(
Then use
int.Parse()
to convert it. ColinMackay.net "Man who stand on hill with mouth open will wait long time for roast duck to drop in." -- Confucius "If a man empties his purse into his head, no man can take it away from him, for an investment in knowledge pays the best interest." -- Joseph E. O'Donnell -
if you are trying to accept only numeric values in your text box, you can use the e.Handle = true of KeyPressEventArgs to cancel the keypress event. You can try the code below. string strnum = "0123456789"; if (strnum.IndexOf(e.KeyChar.ToString())<0) { e.Handled = true; }