c# - Separate textbox value and add to list -
hi trying take numbers added textbox , on button click add numbers list, instance user can input:
123456
so become:
1
2
3 etc
i'm not sure how separate each digit , add list?
list<int> integerlist = new list<int>(); try { int number = int.parse(textbox1.text); (int = 0; < number; i++) { integerlist.add(number); listbox1.items.add(number); }
you can use indexer characters of string.
try { (int = 0; < textbox1.text.length; i++) { integerlist.add(int.parse(textbox1.text[i].tostring()); listbox1.items.add(textbox1.text[i]); } }
you can use linq well.
list<int> integerlist = new list<int>(); textbox1.text.select(c=>convert.toint32(c).tostring()).tolist();
Comments
Post a Comment