SortedSet<T>.CreateSetComparer Method

Definition

Returns an IEqualityComparer object that can be used to create a collection that contains individual sets.

Overloads

CreateSetComparer()

Returns an IEqualityComparer object that can be used to create a collection that contains individual sets.

CreateSetComparer(IEqualityComparer<T>)

Returns an IEqualityComparer object, according to a specified comparer, that can be used to create a collection that contains individual sets.

CreateSetComparer()

Source:
SortedSet.cs
Source:
SortedSet.cs
Source:
SortedSet.cs

Returns an IEqualityComparer object that can be used to create a collection that contains individual sets.

C#
public static System.Collections.Generic.IEqualityComparer<System.Collections.Generic.SortedSet<T>> CreateSetComparer();

Returns

A comparer for creating a collection of sets.

Remarks

The IEqualityComparer object checks for equality at only one level; however, you can chain together comparers at additional levels to perform deeper equality testing.

Calling this method is an O(1) operation.

Applies to

.NET 10 and other versions
Product Versions
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1

CreateSetComparer(IEqualityComparer<T>)

Source:
SortedSet.cs
Source:
SortedSet.cs
Source:
SortedSet.cs

Returns an IEqualityComparer object, according to a specified comparer, that can be used to create a collection that contains individual sets.

C#
public static System.Collections.Generic.IEqualityComparer<System.Collections.Generic.SortedSet<T>> CreateSetComparer(System.Collections.Generic.IEqualityComparer<T>? memberEqualityComparer);
C#
public static System.Collections.Generic.IEqualityComparer<System.Collections.Generic.SortedSet<T>> CreateSetComparer(System.Collections.Generic.IEqualityComparer<T> memberEqualityComparer);

Parameters

memberEqualityComparer
IEqualityComparer<T>

The comparer to use for creating the returned comparer.

Returns

A comparer for creating a collection of sets.

Examples

The following example uses the CreateSetComparer method to create a set of sets. This code example is part of a larger example provided for the SortedSet<T> class.

C#
// Create a set of the sets.
IEqualityComparer<SortedSet<string>> comparer =
    SortedSet<string>.CreateSetComparer();

var allMedia = new HashSet<SortedSet<string>>(comparer);
allMedia.Add(mediaFiles1);
allMedia.Add(mediaFiles2);

Remarks

The memberEqualityComparer and the current SortedSet<T> must have the same definition of equality.

You can use the comparer returned by this method in the SortedSet<T>.SortedSet<T>(IEnumerable<T>, IComparer<T>) constructor to create a hash table of individual sets.

Applies to

.NET 10 and other versions
Product Versions
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1