In this example,I’ll show you How to remove duplicates from listbox in C# Windows Form Application.
C# Code:
1 2 3 4 5 6 7 8 9 10 11 | private void button1_Click(object sender, EventArgs e) { var _items = this.listBox1.Items.Cast<string>().Distinct().ToArray(); this.listBox1.Items.Clear(); foreach (var item in _items) { this.listBox1.Items.Add(item); } } |
Can you explain the working logic of this code?