c# - How can I compare two unordered sequences (list and array) for equality? -


i have string array string str[] = {"a", "b"}

and list<string> lst = new list<string> {"a", "b"}

how can make sure both string array , list contains same values. note: values can in order must have same frequency.

can tell me how in linq?

thanks.

okay, since order not matter frequncies do, need count each key, , check resulting pairs of keys/counts equal:

var first = str.groupby(s => s)                .todictionary(g => g.key, g => g.count());  var second = lst.groupby(s => s)                 .todictionary(g => g.key, g => g.count());  bool equals = first.orderby(kvp => kvp.key)                    .sequenceequals(second.orderby(kvp => kvp.key)); 

Comments

Popular posts from this blog

c# - how to write client side events functions for the combobox items -

exception - Python, pyPdf OCR error: pyPdf.utils.PdfReadError: EOF marker not found -