MemoryExtensions.Replace Method

Definition

Important

Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.

Overloads

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

Replaces all occurrences of oldValue with newValue.

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

Copies source to destination, replacing all occurrences of oldValue with newValue.

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

C#
public static void Replace<T>(this ReadOnlySpan<T> source, Span<T> destination, T oldValue, T newValue, System.Collections.Generic.IEqualityComparer<T>? comparer = default);

Type Parameters

T

Parameters

destination
Span<T>
oldValue
T
newValue
T

Applies to

.NET 10
Product Versions
.NET 10

Replace<T>(Span<T>, T, T, IEqualityComparer<T>)

C#
public static void Replace<T>(this Span<T> span, T oldValue, T newValue, System.Collections.Generic.IEqualityComparer<T>? comparer = default);

Type Parameters

T

Parameters

span
Span<T>
oldValue
T
newValue
T

Applies to

.NET 10
Product Versions
.NET 10

Replace<T>(Span<T>, T, T)

Source:
MemoryExtensions.cs
Source:
MemoryExtensions.cs

Replaces all occurrences of oldValue with newValue.

C#
public static void Replace<T>(this Span<T> span, T oldValue, T newValue) where T : IEquatable<T>;

Type Parameters

T

The type of the elements in the span.

Parameters

span
Span<T>

The span in which the elements should be replaced.

oldValue
T

The value to be replaced with newValue.

newValue
T

The value to replace all occurrences of oldValue.

Applies to

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

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

Source:
MemoryExtensions.cs
Source:
MemoryExtensions.cs

Copies source to destination, replacing all occurrences of oldValue with newValue.

C#
public static void Replace<T>(this ReadOnlySpan<T> source, Span<T> destination, T oldValue, T newValue) where T : IEquatable<T>;

Type Parameters

T

The type of the elements in the spans.

Parameters

source
ReadOnlySpan<T>

The span to copy.

destination
Span<T>

The span into which the copied and replaced values should be written.

oldValue
T

The value to be replaced with newValue.

newValue
T

The value to replace all occurrences of oldValue.

Exceptions

The destination span is shorter than the source span. -or- source and destination overlap but don't refer to the same starting location.

Applies to

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