2个listbox 
吧listbox1中的内容逐条到listbox2中去查找。
找到返回 “1”  没有返回 “0”  
最后存到一个字符串中 
结果: “1,0,1,0,0,0,1”
求助!

解决方案 »

  1.   

     ListBox l = new ListBox();
                ListBox l2 = new ListBox();
                l.Items.Add("1");
                l.Items.Add("2");
                l.Items.Add("3");            l2.Items.Add("1");
                l2.Items.Add("12");
                l2.Items.Add("112");            ArrayList list = new ArrayList();
                foreach (object o in l.Items)
                {
                    if (l2.Items.IndexOf(o) == -1)
                    {
                        list.Add(o);
                    }
                }
      

  2.   

    ListBox l = new ListBox(); 
                ListBox l2 = new ListBox(); 
                l.Items.Add("1"); 
                l.Items.Add("2"); 
                l.Items.Add("3");             l2.Items.Add("1"); 
                l2.Items.Add("12"); 
                l2.Items.Add("112");             ArrayList list = new ArrayList(); 
                foreach (object o in l.Items) 
                { 
                    if (l2.Items.IndexOf(o) == -1) 
                    { 
                        list.Add(o); 
                    } 
                }       foreach (object o in l2.Items) 
                { 
                    if (l.Items.IndexOf(o) == -1) 
                    { 
                        list.Add(o); 
                    } 
                } 
      

  3.   


    string result = "";
    for(int i=0;i<listBox1.Items.Count;i++)
    {
        int index = listBox2.FindString(listBox1.Items[i].ToString());
        if(index > -1)
            if(i!=listBox1.Items.Count - 1)
                result += "1,";
            else 
                result += "1";
        else
            if(i!=listBox1.Items.Count - 1)
                result += "0,";
            else 
                result += "0";
    }
      

  4.   


    System.Collections.ArrayList array = new System.Collections.ArrayList();
                
                    foreach (object obj in this.listBox1.Items)
                    {
                        if (this.listBox1.Items.IndexOf(obj) != -1)
                            array.Add(1);
                        else
                            array.Add(2);
                    }
                  string[] strs=(string [])   array.ToArray(typeof(string));
      

  5.   


                    System.Collections.ArrayList array = new System.Collections.ArrayList();            
                    foreach (object obj in this.listBox1.Items)
                    {
                        if (this.listBox2.Items.IndexOf(obj) != -1)
                            array.Add(1);
                        else
                            array.Add(0);
                    }
                    string[] strs=(string [])   array.ToArray(typeof(string));