Skip to content

Diff.CalculateSections Method

Lasse Vågsæther Karlsen edited this page May 3, 2017 · 1 revision

This method calculates what is known as a "diff section", a portion of the two collections that either is similar or is not. A section can encompass from zero to N elements on both sides. At least one side will have elements.

Method signature:

public static IEnumerable<DiffSection> CalculateSections<T>(
    IList<T> collection1,
    IList<T> collection2,
    IEqualityComparer<T> comparer = null)

The method takes the following parameters, in signature order:

  • IList<T> collection1

    This specifies one of the two collections that will be compared.

    Note the type, to signal that the diff engine needs fast random access to the collection, IList<T> is used instead of the customary IEnumerable<T> of most similar implementations.

    This parameter cannot be null or a ArgumentNullException will be thrown.

  • IList<T> collection2

    This specifies the other of the two collections that will be compared.

    Note the type, to signal that the diff engine needs fast random access to the collection, IList<T> is used instead of the customary IEnumerable<T> of most similar implementations.

    This parameter cannot be null or a ArgumentNullException will be thrown.

  • IEqualityComparer<T> comparer

    This optional parameter specifies an IEqualityComparer<T> implementation that knows how to compare two elements of type T.

    If none is provided (pass null, which is also the default value), then EqualityComparer<T>.Default will be used.

It returns:

  • IEnumerable<DiffSection>

Clone this wiki locally