Table of Contents

Class ObservableList<T>

Namespace
CarinaStudio.Collections
Assembly
CarinaStudio.AppBase.Core.dll

Implementation of IList<T> which also implements INotifyCollectionChanged and INotifyPropertyChanged.

public class ObservableList<T> : IList, ICollection, IList<T>, ICollection<T>, INotifyCollectionChanged, INotifyPropertyChanged, IReadOnlyList<T>, IReadOnlyCollection<T>, IEnumerable<T>, IEnumerable

Type Parameters

T

Type of element.

Inheritance
ObservableList<T>
Implements
Inherited Members
Extension Methods

Constructors

ObservableList(IEnumerable<T>?)

Initialize new ObservableList<T> instance.

public ObservableList(IEnumerable<T>? elements = null)

Parameters

elements IEnumerable<T>

Initial elements.

ObservableList(int)

Initialize new ObservableList<T> instance.

public ObservableList(int capacity)

Parameters

capacity int

Initial capacity.

Properties

Capacity

Get capacity of the list.

public int Capacity { get; }

Property Value

int

Count

Get number of elements.

public int Count { get; }

Property Value

int

this[int]

Get or set element.

public T this[int index] { get; set; }

Parameters

index int

Index of element.

Property Value

T

Element.

Methods

Add(T)

Add element to list.

public int Add(T element)

Parameters

element T

Element to add.

Returns

int

Index of added element in list.

AddRange(IEnumerable<T>)

Add elements to list.

public void AddRange(IEnumerable<T> elements)

Parameters

elements IEnumerable<T>

Elements to add.

AsReadOnly()

Make the list as read-only IList<T>.

public IList<T> AsReadOnly()

Returns

IList<T>

Read-only IList<T>, the instance also implements INotifyCollectionChanged and IReadOnlyList<T>.

BinarySearch(T)

Use binary-search to find given element.

public int BinarySearch(T element)

Parameters

element T

Element to be found.

Returns

int

Index of found element, or bitwise complement of index of proper position to put element.

Remarks

The type of element must implement either IComparable<T> or IComparable, otherwise a NotSupportedException exception will be thrown.

BinarySearch(T, IComparer<T>)

Use binary-search to find given element.

public int BinarySearch(T element, IComparer<T> comparer)

Parameters

element T

Element to be found.

comparer IComparer<T>

IComparer<T> to compare elements.

Returns

int

Index of found element, or bitwise complement of index of proper position to put element.

BinarySearch(T, Comparison<T>)

Use binary-search to find given element.

public int BinarySearch(T element, Comparison<T> comparison)

Parameters

element T

Element to be found.

comparison Comparison<T>

Comparison function.

Returns

int

Index of found element, or bitwise complement of index of proper position to put element.

BinarySearch<TKey>(TKey, Func<T, TKey>)

Use binary-search to find given element by key.

public int BinarySearch<TKey>(TKey key, Func<T, TKey> keyGetter) where TKey : IComparable<TKey>

Parameters

key TKey

Key of element to be found.

keyGetter Func<T, TKey>

Method to get key from element.

Returns

int

Index of found element, or bitwise complement of index of proper position to put element.

Type Parameters

TKey

Type of key of element.

BinarySearch<TKey>(TKey, Func<T, TKey>, Comparison<TKey>)

Use binary-search to find given element by key.

public int BinarySearch<TKey>(TKey key, Func<T, TKey> keyGetter, Comparison<TKey> comparison)

Parameters

key TKey

Key of element to be found.

keyGetter Func<T, TKey>

Method to get key from element.

comparison Comparison<TKey>

Comparison function.

Returns

int

Index of found element, or bitwise complement of index of proper position to put element.

Type Parameters

TKey

Type of key of element.

Clear()

Clear all elements.

public void Clear()

Contains(T)

Check whether given element is contained in list or not.

public bool Contains(T element)

Parameters

element T

Element.

Returns

bool

True if element is contained in list.

CopyTo(int, T[], int, int)

Copy elements to array.

public void CopyTo(int index, T[] array, int arrayIndex, int count)

Parameters

index int

Index of first element in list to copy.

array T[]

Array to place copied elements.

arrayIndex int

Index of first position in array to place copied elements.

count int

Number of elements to copy.

CopyTo(T[], int)

Copy elements to array.

public void CopyTo(T[] array, int arrayIndex)

Parameters

array T[]

Array to place copied elements.

arrayIndex int

Index of first position in array to place copied elements.

GetEnumerator()

Get IEnumerator<T> to enumerate elements.

public IEnumerator<T> GetEnumerator()

Returns

IEnumerator<T>

IEnumerator<T>.

IndexOf(T)

Get index of given element in list.

public int IndexOf(T element)

Parameters

element T

Element.

Returns

int

Index of element in list, or -1 if element is not contained in list.

Insert(int, T)

Insert element at given position.

public void Insert(int index, T element)

Parameters

index int

Index of position to insert element.

element T

Element to insert.

InsertRange(int, IEnumerable<T>)

Insert elements at given position.

public void InsertRange(int index, IEnumerable<T> elements)

Parameters

index int

Index of position to insert elements.

elements IEnumerable<T>

Elements to insert.

IsEmpty()

Check whether the list is empty or not.

public bool IsEmpty()

Returns

bool

True if the list is empty.

IsNotEmpty()

Check whether the list is not empty or not.

public bool IsNotEmpty()

Returns

bool

True if the list is not empty.

Move(int, int)

Move element in the list.

public void Move(int index, int newIndex)

Parameters

index int

Index of element to move.

newIndex int

New index of element.

MoveRange(int, int, int)

Move elements in the list.

public void MoveRange(int index, int newIndex, int count)

Parameters

index int

Index of first element to move.

newIndex int

New index of first moved element.

count int

Number of elements to move.

Remove(T)

Remove first found of given element.

public bool Remove(T element)

Parameters

element T

Element to remove.

Returns

bool

True if element has been removed.

RemoveAll(Predicate<T>)

Remove elements which match given condition from list.

public int RemoveAll(Predicate<T> predicate)

Parameters

predicate Predicate<T>

Function to check whether log matches given condition or not.

Returns

int

Number of removed elements.

RemoveAt(int)

Remove element at given position.

public void RemoveAt(int index)

Parameters

index int

Index of element to remove.

RemoveRange(int, int)

Remove elements.

public void RemoveRange(int index, int count)

Parameters

index int

Index of first element to remove.

count int

Number of elements to remove.

Reverse()

Make given list as reversed IList<T>.

public IList<T> Reverse()

Returns

IList<T>

Reversed IList<T> which also implements INotifyCollectionChanged and IReadOnlyList<T>.

ReverseAsReadOnly()

Make given list as reversed and read-only IList<T>.

public IList<T> ReverseAsReadOnly()

Returns

IList<T>

Reversed read-only IList<T> which also implements INotifyCollectionChanged and IReadOnlyList<T>.

ToArray()

Copy elements to array.

public T[] ToArray()

Returns

T[]

Array of copied elements

ToArray(int, int)

Copy elements to array.

public T[] ToArray(int index, int count)

Parameters

index int

Index of first element in list to copy.

count int

Number of elements to copy.

Returns

T[]

Array of copied elements

TrimExcess()

Set the capacity to the actual number of elements in list.

public void TrimExcess()

Events

CollectionChanged

Raised when list changed.

public event NotifyCollectionChangedEventHandler? CollectionChanged

Event Type

NotifyCollectionChangedEventHandler

PropertyChanged

Raised when property changed.

public event PropertyChangedEventHandler? PropertyChanged

Event Type

PropertyChangedEventHandler