i have arraylist string(codes) , want control whether string duplicate in arraylist. if string duplicate want other code arraylist.
my code:
private void btn_create_click(object sender, eventargs e) { arraylist list = new arraylist(); try { list = dodeserialize(); } catch (exception ex) { lbl_status.text = ex.message; } string code = getcode(7); code = "2 - " + code; int test = list.indexof(code); txt_code.text = code; lbl_status.text = "code wurde erstellt"; list.add(code); doserialize(list); }
add in place of list.add(code);
. method checks whether item in array list.
if(!list.contains(code)) { // code not exist in list, add list.add(code); } else { // code exists, here. }
see here more information list<t>.contains()
method.
Comments
Post a Comment