Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using IEnumerable.Except

I got 3 listViews 2 textbox and 2 buttons in WinForm.

Program Description: The program adds numbers to the listview by typing in numbers in the textbox and clicking the add button

Goal: I want to be able to use the IEnumerable.Except method to output only the unique numbers in listView3, for example in the picture below the unique numbers are 3 and 7 in listView1 and listView2. ListViewItem lvi = new ListViewItem(textBox1.Text); listView1.Items.Add(lvi);

ListViewItem lv = new ListViewItem(textBox2.Text);
listView2.Items.Add(lv);

//im doing somthing wrong here...
var nonintersect = listView1.Except(listView2).Union(listView2.Except(listView1));

//populate listview3 with the unique numbers...
// foreach (item )
// {

// }

Error Message: System.Windows.Forms.ListView' does not contain a definition for 'Except' and no extension method 'Except' accepting a first argument of type 'System.Windows.Forms.ListView' could be found (are you missing a using directive or an assembly reference?)

enter image description here

like image 661
taji01 Avatar asked Aug 13 '15 22:08

taji01


1 Answers

It's called Symmetric DIfference and it's simple as that.

var nonintersect = listView1.Except(listView2).Union(listView2.Except(listView1));

Source Origin

like image 93
Orel Eraki Avatar answered Sep 17 '22 01:09

Orel Eraki