Skip to content

IEnumerable Extension Methods

OtisInf edited this page Feb 19, 2013 · 1 revision

The following extension methods are defined for the IEnumerable<T> type:

  • ReadOnlyCollection<T> ToReadOnlyCollection<T>().
    Creates a new ReadOnlyCollection<T> with the contents of the IEnumerable<T> specified.
  • HashSet<T> ToHashSet<T>().
    Creates a new HashSet<T> with the contents of the IEnumerable<T> specified.
  • bool SetEqual<T>(IEnumerable<T> toCompareWith)
    Checks whether the enumerable toCompareWith is equal to the source enumerable specified, element wise. If elements are in a different order, the method will still return true. This is different from SequenceEqual which does take order into account. Comparisons use the default comparer.
  • bool SetEqual<T>(IEnumerable<T> toCompareWith, IEqualityComparer<T> comparer)
    Checks whether the enumerable toCompareWith is equal to the source enumerable specified, element wise. If elements are in a different order, the method will still return true. This is different from SequenceEqual which does take order into account. The passed in comparer is used to compare the elements in the two sequences. If comparer is null, the default comparer is used.