WebApr 3, 2024 · Given two unsorted arrays, check whether both arrays have the same set of elements or not. Examples: Input : A = {2, 5, 6, 8, 10, 2, 2} B = {2, 5, 5, 6, 8, 5, 6} Output : No Input : A = {2, 5, 6, 8, 2, 10, 2} B = {2, 5, 6, 8, 2, 10, 2} Output : Yes Input : A = {2, 5, 8, 6, 10, 2, 2} B = {2, 5, 6, 8, 2, 10, 2} Output : Yes WebMay 20, 2024 · If the lengths are different, then the contents can't possibly be an exact match. If the lengths are the same, then you do a full check. To clarify Kurt's answer about converting from a HashSet back to an array, you can get back an array with the same items, but they won't necessarily be in the original order.
Check if 2 arrays have the same elements, but different order
WebJun 30, 2024 · Use Comparer. Both method takes comparer as second argument. Let's compare by LastName. public class PersonComparer : IEqualityComparer { … WebSep 16, 2015 · 3 Answers Sorted by: 15 Checking whether two lists are equal is naturally an O (n) operation. So yes, your code looks efficient. Note that you could also replace your for loop with Enumerable.SequenceEqual climbing wall salt lake city
Check whether two lists have the same items in C#
WebThe Cube class implements the IEquatable.Equals method so that two cubes are considered equal if their dimensions are the same. In this example, the Contains … WebMar 11, 2024 · This example shows how to use LINQ to compare two lists of strings and output those lines that are in names1.txt but not in names2.txt. To create the data files Copy names1.txt and names2.txt to your solution folder as shown in How to combine and compare string collections (LINQ) (C#). Example C# WebJun 24, 2024 · Combine elements of two lists into another list. I have two lists, I need to make another list with the same elements than the other lists. But elements on this list … climbing wall rugby