I have 2 ListBoxs
which has a set of items. The count between each ListBoxs
can be same or different, if the count is same, I want to check if items between the ListBoxs
are same. The items can be disordered or ordered as shown below:
ListBox1 = { "C++", "C#", "Visual Basic" };
ListBox2 = { "C#", "Visual Basic", "C++" };
Kindly help.
You could use Linq's All function
var ListBox1 = new string[] { "C++", "C#", "Visual Basic" };
var ListBox2 = new string[] { "C#", "Visual Basic", "C++" };
bool same = ListBox1.Length == ListBox2.Length
&& ListBox1.All(s => ListBox2.Contains(s));
You can simply use HashSet:
var hashSet1 = new HashSet<string> { "C++", "C#", "Visual Basic" };
var hashSet2 = new HashSet<string> { "C#", "Visual Basic", "C++" };
var result = hashSet1.SetEquals(hashSet2);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With