MemoryExtensions.CommonPrefixLength Method

Definition

Overloads

CommonPrefixLength<T>(ReadOnlySpan<T>, ReadOnlySpan<T>)

Finds the length of any common prefix shared between span and other.

CommonPrefixLength<T>(Span<T>, ReadOnlySpan<T>)

Finds the length of any common prefix shared between span and other.

CommonPrefixLength<T>(ReadOnlySpan<T>, ReadOnlySpan<T>, IEqualityComparer<T>)

Determines the length of any common prefix shared between span and other.

CommonPrefixLength<T>(Span<T>, ReadOnlySpan<T>, IEqualityComparer<T>)

Finds the length of any common prefix shared between span and other.

CommonPrefixLength<T>(ReadOnlySpan<T>, ReadOnlySpan<T>)

Source:
MemoryExtensions.cs
Source:
MemoryExtensions.cs
Source:
MemoryExtensions.cs

Finds the length of any common prefix shared between span and other.

C#
public static int CommonPrefixLength<T>(this ReadOnlySpan<T> span, ReadOnlySpan<T> other);

Type Parameters

T

The type of the elements in the spans.

Parameters

span
ReadOnlySpan<T>

The first sequence to compare.

other
ReadOnlySpan<T>

The second sequence to compare.

Returns

The length of the common prefix shared by the two spans. If there's no shared prefix, 0 is returned.

Applies to

.NET 9 and other versions
Product Versions
.NET 7, 8, 9

CommonPrefixLength<T>(Span<T>, ReadOnlySpan<T>)

Source:
MemoryExtensions.cs
Source:
MemoryExtensions.cs
Source:
MemoryExtensions.cs

Finds the length of any common prefix shared between span and other.

C#
public static int CommonPrefixLength<T>(this Span<T> span, ReadOnlySpan<T> other);

Type Parameters

T

The type of the elements in the spans.

Parameters

span
Span<T>

The first sequence to compare.

other
ReadOnlySpan<T>

The second sequence to compare.

Returns

The length of the common prefix shared by the two spans. If there's no shared prefix, 0 is returned.

Applies to

.NET 9 and other versions
Product Versions
.NET 7, 8, 9

CommonPrefixLength<T>(ReadOnlySpan<T>, ReadOnlySpan<T>, IEqualityComparer<T>)

Source:
MemoryExtensions.cs
Source:
MemoryExtensions.cs
Source:
MemoryExtensions.cs

Determines the length of any common prefix shared between span and other.

C#
public static int CommonPrefixLength<T>(this ReadOnlySpan<T> span, ReadOnlySpan<T> other, System.Collections.Generic.IEqualityComparer<T>? comparer);

Type Parameters

T

The type of the elements in the sequences.

Parameters

span
ReadOnlySpan<T>

The first sequence to compare.

other
ReadOnlySpan<T>

The second sequence to compare.

comparer
IEqualityComparer<T>

The IEqualityComparer<T> implementation to use when comparing elements, or null to use the default IEqualityComparer<T> for the type of an element.

Returns

The length of the common prefix shared by the two spans. If there's no shared prefix, 0 is returned.

Applies to

.NET 9 and other versions
Product Versions
.NET 7, 8, 9

CommonPrefixLength<T>(Span<T>, ReadOnlySpan<T>, IEqualityComparer<T>)

Source:
MemoryExtensions.cs
Source:
MemoryExtensions.cs
Source:
MemoryExtensions.cs

Finds the length of any common prefix shared between span and other.

C#
public static int CommonPrefixLength<T>(this Span<T> span, ReadOnlySpan<T> other, System.Collections.Generic.IEqualityComparer<T>? comparer);

Type Parameters

T

The type of the elements in the spans.

Parameters

span
Span<T>

The first sequence to compare.

other
ReadOnlySpan<T>

The second sequence to compare.

comparer
IEqualityComparer<T>

The IEqualityComparer<T> implementation to use when comparing elements, or null to use the default IEqualityComparer<T> for the type of an element.

Returns

The length of the common prefix shared by the two spans. If there's no shared prefix, 0 is returned.

Applies to

.NET 9 and other versions
Product Versions
.NET 7, 8, 9