Class ObservableCollection<T>
Represent a collection of items that fire events when it is modified.
Inheritance
Implements
Inherited Members
Namespace: netDxf.Collections
Assembly: CADability.dll
Syntax
public class ObservableCollection<T> : IList<T>, ICollection<T>, IEnumerable<T>, IEnumerable
Type Parameters
| Name | Description |
|---|---|
| T | Type of items. |
Constructors
| Improve this Doc View SourceObservableCollection()
Initializes a new instance of ObservableCollection.
Declaration
public ObservableCollection()
ObservableCollection(Int32)
Initializes a new instance of ObservableCollection and has the specified initial capacity.
Declaration
public ObservableCollection(int capacity)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Int32 | capacity | The number of items the collection can initially store. |
Properties
| Improve this Doc View SourceCount
Gets the number of object contained in the collection.
Declaration
public int Count { get; }
Property Value
| Type | Description |
|---|---|
| System.Int32 |
IsReadOnly
Gets a value indicating whether the collection is read-only.
Declaration
public virtual bool IsReadOnly { get; }
Property Value
| Type | Description |
|---|---|
| System.Boolean |
Item[Int32]
Gets or sets the object at the specified index.
Declaration
public T this[int index] { get; set; }
Parameters
| Type | Name | Description |
|---|---|---|
| System.Int32 | index | The zero-based index of the element to get or set. |
Property Value
| Type | Description |
|---|---|
| T | The object at the specified index. |
Methods
| Improve this Doc View SourceAdd(T)
Adds an object to the collection.
Declaration
public void Add(T item)
Parameters
| Type | Name | Description |
|---|---|---|
| T | item | The object to add to the collection. |
AddRange(IEnumerable<T>)
Adds an object list to the end of the collection.
Declaration
public void AddRange(IEnumerable<T> collection)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Collections.Generic.IEnumerable<T> | collection | The collection whose elements should be added. |
Clear()
Removes all object from the collection.
Declaration
public void Clear()
Contains(T)
Determines whether an object is in the collection.
Declaration
public bool Contains(T item)
Parameters
| Type | Name | Description |
|---|---|---|
| T | item | The object to locate in the collection. |
Returns
| Type | Description |
|---|---|
| System.Boolean | True if item is found in the collection; otherwise, false. |
CopyTo(T[], Int32)
Copies the entire collection to a compatible one-dimensional array, starting at the specified index of the target array.
Declaration
public void CopyTo(T[] array, int arrayIndex)
Parameters
| Type | Name | Description |
|---|---|---|
| T[] | array | The one-dimensional System.Array that is the destination of the elements copied from the collection. The System.Array must have zero-based indexing. |
| System.Int32 | arrayIndex | The zero-based index in array at which copying begins. |
GetEnumerator()
Returns an enumerator that iterates through the collection.
Declaration
public IEnumerator<T> GetEnumerator()
Returns
| Type | Description |
|---|---|
| System.Collections.Generic.IEnumerator<T> | An enumerator that can be used to iterate through the collection. |
IndexOf(T)
Searches for the specified object and returns the zero-based index of the first occurrence within the entire collection.
Declaration
public int IndexOf(T item)
Parameters
| Type | Name | Description |
|---|---|---|
| T | item | The object to locate in the collection. |
Returns
| Type | Description |
|---|---|
| System.Int32 | The zero-based index of the first occurrence of item within the entire collection, if found; otherwise, –1. |
Insert(Int32, T)
Inserts an object into the collection at the specified index.
Declaration
public void Insert(int index, T item)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Int32 | index | The zero-based index at which item should be inserted. |
| T | item | The object to insert. The value can not be null. |
OnAddItemEvent(T)
Declaration
protected virtual void OnAddItemEvent(T item)
Parameters
| Type | Name | Description |
|---|---|---|
| T | item |
OnBeforeAddItemEvent(T)
Declaration
protected virtual bool OnBeforeAddItemEvent(T item)
Parameters
| Type | Name | Description |
|---|---|---|
| T | item |
Returns
| Type | Description |
|---|---|
| System.Boolean |
OnBeforeRemoveItemEvent(T)
Declaration
protected virtual bool OnBeforeRemoveItemEvent(T item)
Parameters
| Type | Name | Description |
|---|---|---|
| T | item |
Returns
| Type | Description |
|---|---|
| System.Boolean |
OnRemoveItemEvent(T)
Declaration
protected virtual void OnRemoveItemEvent(T item)
Parameters
| Type | Name | Description |
|---|---|---|
| T | item |
Remove(T)
Removes the first occurrence of a specific object from the collection
Declaration
public bool Remove(T item)
Parameters
| Type | Name | Description |
|---|---|---|
| T | item | The object to remove from the collection. |
Returns
| Type | Description |
|---|---|
| System.Boolean | True if object is successfully removed; otherwise, false. |
Remove(IEnumerable<T>)
Removes the first occurrence of a specific object from the collection
Declaration
public void Remove(IEnumerable<T> items)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Collections.Generic.IEnumerable<T> | items | The list of objects to remove from the collection. |
RemoveAt(Int32)
Removes the object at the specified index of the collection.
Declaration
public void RemoveAt(int index)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Int32 | index | The zero-based index of the object to remove. |
Reverse()
Reverses the order of the elements in the entire list.
Declaration
public void Reverse()
Sort()
Sorts the elements in the entire System.Collections.Generic.List<T> using the default comparer.
Declaration
public void Sort()
Sort(IComparer<T>)
Sorts the elements in a range of elements in System.Collections.Generic.List<T> using the specified comparer.
Declaration
public void Sort(IComparer<T> comparer)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Collections.Generic.IComparer<T> | comparer | The System.Collections.Generic.IComparer<T> implementation to use when comparing elements, or null to use the default comparer System.Collections.Generic.Comparer<T>.Default. |
Sort(Comparison<T>)
Sorts the elements in the entire System.Collections.Generic.List<T> using the specified System.Comparison<T>.
Declaration
public void Sort(Comparison<T> comparision)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Comparison<T> | comparision | The System.Comparison<T> to use when comparing elements. |
Sort(Int32, Int32, IComparer<T>)
Sorts the elements in a range of elements in System.Collections.Generic.List<T> using the specified comparer.
Declaration
public void Sort(int index, int count, IComparer<T> comparer)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Int32 | index | The zero-based starting index of the range to sort. |
| System.Int32 | count | The length of the range to sort. |
| System.Collections.Generic.IComparer<T> | comparer | The System.Collections.Generic.IComparer<T> implementation to use when comparing elements, or null to use the default comparer System.Collections.Generic.Comparer<T>.Default. |
Events
| Improve this Doc View SourceAddItem
Declaration
public event ObservableCollection<T>.AddItemEventHandler AddItem
Event Type
| Type | Description |
|---|---|
| ObservableCollection.AddItemEventHandler<> |
BeforeAddItem
Declaration
public event ObservableCollection<T>.BeforeAddItemEventHandler BeforeAddItem
Event Type
| Type | Description |
|---|---|
| ObservableCollection.BeforeAddItemEventHandler<> |
BeforeRemoveItem
Declaration
public event ObservableCollection<T>.BeforeRemoveItemEventHandler BeforeRemoveItem
Event Type
| Type | Description |
|---|---|
| ObservableCollection.BeforeRemoveItemEventHandler<> |
RemoveItem
Declaration
public event ObservableCollection<T>.RemoveItemEventHandler RemoveItem
Event Type
| Type | Description |
|---|---|
| ObservableCollection.RemoveItemEventHandler<> |
Explicit Interface Implementations
| Improve this Doc View SourceICollection<T>.Add(T)
Declaration
void ICollection<T>.Add(T item)
Parameters
| Type | Name | Description |
|---|---|---|
| T | item |
IList<T>.Insert(Int32, T)
Declaration
void IList<T>.Insert(int index, T item)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Int32 | index | |
| T | item |
IEnumerable.GetEnumerator()
Declaration
IEnumerator IEnumerable.GetEnumerator()
Returns
| Type | Description |
|---|---|
| System.Collections.IEnumerator |