Experts Exchange Solution brought to you by
"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.
bool arraysAreEqual = (array1.Length == array2.Length)
&& new HashSet<T>(array1).SetEquals(array2);
Open in new window
SortedDictionary<T, int> dict1 = new SortedDictionary<T, int>();
SortedDictionary<T, int> dict2 = new SortedDictionary<T, int>();
foreach (t in array1)
dict1[t]++; // count occurences
foreach (t in array2)
dict2[t]++; // count occurences
bool areArraysEqual = dict1.SequenceEqual(dict2);
static bool AreArraysEqual<T>(T array1, T array2)
if (array1.Length != array2.Length)
EqualityComparer<T> comparer = EqualityComparer<T>.Default;
for (int i = 0; i < array1.Length; i++)
if (!comparer.Equals(array1[i], array2[i])) return false;
Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.
From novice to tech pro — start learning today.
Premium members can enroll in this course at no extra cost.