Skip to content

CollectionChangedArgs<T> Struct

Provides data for the CollectionChangedEventHandler<T> events.

C#
public readonly struct CollectionChangedArgs<T> : IEquatable<CollectionChangedArgs<T>>

T
The type of the items in the collection.

Implements IEquatable<CollectionChangedArgs<T>>

Gets the action that specifies how the collection changed.

C#
public NotifyCollectionChangedAction Action { get; }

Gets the index at which the new item was added.

C#
public int NewIndex { get; }

Gets the index at which the old item was removed.

C#
public int OldIndex { get; }

Gets the items that were added.

C#
public ReadOnlyMemory<T> OldItems { get; }

Gets the items that were removed.

C#
public ReadOnlyMemory<T> NewItems { get; }

Creates a new instance of CollectionChangedArgs<T> with the Add action with only one item.

C#
public static CollectionChangedArgs<T> Add(T newItem, int startingIndex)

newItem T
The new item that was added.

startingIndex int
The index at which the new item was added.

CollectionChangedArgs<T>
A new instance of CollectionChangedArgs<T>.

Creates a new instance of CollectionChangedArgs<T> with the Add action with multiple items.

C#
public static CollectionChangedArgs<T> Add(ReadOnlySpan<T> newItems, int startingIndex)

newItems ReadOnlySpan<T>
The new items that were added.

startingIndex int
The index at which the new items were added.

CollectionChangedArgs<T>
A new instance of CollectionChangedArgs<T>.

Creates a new instance of CollectionChangedArgs<T> with the Remove action with only one item.

C#
public static CollectionChangedArgs<T> Remove(T oldItem, int removedIndex)

oldItem T
The old item that was removed.

removedIndex int
The index at which the old item was removed.

CollectionChangedArgs<T>
A new instance of CollectionChangedArgs<T>.

Creates a new instance of CollectionChangedArgs<T> with the Remove action with multiple items.

C#
public static CollectionChangedArgs<T> Remove(ReadOnlySpan<T> oldItems, int removedIndex)

oldItems ReadOnlySpan<T>
The old items that were removed.

removedIndex int
The index at which the old items were removed.

CollectionChangedArgs<T>
A new instance of CollectionChangedArgs<T>.

Creates a new instance of CollectionChangedArgs<T> with the Replace action with only one item.

C#
public static CollectionChangedArgs<T> Replace(T oldItem, T newItem, int index)

oldItem T
The old item that was replaced.

newItem T
The new item that was added.

index int
The index at which the item was replaced.

CollectionChangedArgs<T>
A new instance of CollectionChangedArgs<T>.

Creates a new instance of CollectionChangedArgs<T> with the Replace action with multiple items.

C#
public static CollectionChangedArgs<T> Replace(ReadOnlySpan<T> oldItems, ReadOnlySpan<T> newItems, int startingIndex)

oldItems ReadOnlySpan<T>
The old items that were replaced.

newItems ReadOnlySpan<T>
The new items that were added.

startingIndex int
The index at which the items were replaced.

CollectionChangedArgs<T>
A new instance of CollectionChangedArgs<T>.

Creates a new instance of CollectionChangedArgs<T> with the Reset action.

C#
public static CollectionChangedArgs<T> Clear(ReadOnlySpan<T> items, int newIndex = 0, int oldIndex = 0)

items ReadOnlySpan<T>
The items that were cleared.

newIndex int
The index at which the items were cleared.

oldIndex int
The index at which the items were cleared.

CollectionChangedArgs<T>
A new instance of CollectionChangedArgs<T>.

Checks if the current instance is equal to another CollectionChangedArgs<T> instance.

C#
public bool Equals(CollectionChangedArgs<T> other)

other CollectionChangedArgs<T>
The other instance to compare with.

bool
true if the instances are equal; otherwise, false.

Checks if the current instance is the same type as the given object and if they are equal.

C#
public override bool Equals(object? obj)

obj object
The object to compare with.

bool
true if the object is a CollectionChangedArgs<T> and is equal to the current instance; otherwise, false.

Generates a hash code for the current instance.

C#
public override int GetHashCode()

int
A hash code for the current instance.