I need to compare two lists and only know if they contain the same values or not. I am not going to do anything with the differences.
What would be the best way to achieve this in C #?
I know that I can loop through lists, but I want to know if any LINQ / extenstion built-in method can achieve this, which provides better performance. Tried Except / Intersect, but don’t know if they are the most suitable to achieve this.
Update: Lists will not contain duplicates.
? , {2, 1, 1} , {1, 2}? ( , ... SequenceEqual.)
SequenceEqual
, "" , :
:
if (!list1.Except(list2).Any() && !list2.Except(list1).Any())
var set = new HashSet<int>(list1); // Adjust case accordingly if (set.SetEquals(list2)) { // Lists were equal }
, : , , , ...
Source: https://habr.com/ru/post/1790919/More articles:Why do some class classes have an "empty" instance method in addition to the class method? - collectionshttps://translate.googleusercontent.com/translate_c?depth=1&pto=aue&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/1790915/disabling-all-interrupts-to-protect-cpu-register-state-on-multi-processor-systems&usg=ALkJrhh78_Dt_TQo0gtzuI6Fa1KAOTosFQWhy does the DropDownList.SelectedIndexChanged event not fire? - javascriptBlock incoming / outgoing SMS on Android - androidDoes iOS 4.2 SDK support custom fonts? - iphoneWhat is the difference between managed and unmanaged dlls - dllIs layered ConcurrentDictionary still thread protected? - c #HQL JoinTable Not Available - hibernateAndroid Facebook SDK - problem with authorizeCallback () - androidCan you force SQLCMD to immediately run each statement in a script without using "GO"? - sql-serverAll Articles