c# - Don't know how contains works to remove duplicates -


trying see if number in listbox, if not add it.

i've had around i'm getting confused. tried using contains i'm using invalid arguments, how tell i'm doing wrong?

public void sorteven() {     string userinput = textbox1.text;     string[] numberarray = userinput.split(',');     foreach (string in numberarray)     {         int x = int32.parse(i);         if (x % 2 == 0)         {             if (!listbox1.items.contains(i)) //error here, says invalid arguments             {             listbox1.items.add(i);             }         }     } 

if there better/more efficient alternative i'm doing, love know too.

do want add distinct numbers in listbox?

you try

foreach (string in numberarray.distinct()) {     int x = int32.parse(i);     if (x % 2 == 0)     {         listbox1.items.add(i);     } } 

Comments

Popular posts from this blog

java - How to specify maven bin in eclipse maven plugin? -

single sign on - Logging into Plone site with credentials passed through HTTP -

php - Why does AJAX not process login form? -