OBJECT EQUALITY COMPARISON C#

Any two objects of same type has to be compared for equality. For this we have an internal function as Enumerable.SequenceEqual(). But this can compare equality of two objects provided only if the elements are in their respective order.
i. .e if A={1, 2, 3} and B={1, 2, 3} then they are equal and returns true but if B={3, 1, 2} then these two objects are not equal from above function.
But in this case where the order of the elements of the object can be ignored while comparing by our own method extension function, defined as below:

public static bool UnorderedEqual<T>(this ICollection<T> a, ICollection<T> b)
        {
            // 1
            // Require that the counts are equal
            if (a.Count != b.Count)
            {
                return false;
            }
            // 2
            // Initialize new Dictionary of the type
            Dictionary<T, int> d = new Dictionary<T, int>();
            // 3
            // Add each key’s frequency from collection A to the Dictionary
            foreach (T item in a)
            {
                int c;
                if (d.TryGetValue(item, out c))
                {
                    d[item] = c + 1;
                }
                else
                {
                    d.Add(item, 1);
                }
            }
            // 4
            // Add each key’s frequency from collection B to the Dictionary
            // Return early if we detect a mismatch
            foreach (T item in b)
            {
                int c;
                if (d.TryGetValue(item, out c))
                {
                    if (c == 0)
                    {
                        return false;
                    }
                    else
                    {
                        d[item] = c – 1;
                    }
                }
                else
                {
                    // Not in dictionary
                    return false;
                }
            }
            // 5
            // Verify that all frequencies are zero
            foreach (int v in d.Values)
            {
                if (v != 0)
                {
                    return false;
                }
            }
            // 6
            // We know the collections are equal
            return true;
        }