Table of Contents

Class ObservableStack<T>

Namespace
Loehnert.Utility.Collections
Assembly
Loehnert.Utility.dll

Class for a stack, implementing INotifyCollectionChanged.

public class ObservableStack<T> : INotifyCollectionChanged, IEnumerable<T>, ICollection, IEnumerable

Type Parameters

T

Type of stack objects.

Inheritance
ObservableStack<T>
Implements
Inherited Members
Extension Methods

Constructors

ObservableStack()

Initializes a new instance of the ObservableStack<T> class that is empty and has the default initial capacity.

public ObservableStack()

ObservableStack(IEnumerable<T>)

Initializes a new instance of the ObservableStack<T> class that contains elements copied from the specified collection and has sufficient capacity to accommodate the number of elements copied.

public ObservableStack(IEnumerable<T> collection)

Parameters

collection IEnumerable<T>

The collection to copy elements from.

Exceptions

ArgumentNullException

Thrown when collection is null.

ObservableStack(int)

Initializes a new instance of the ObservableStack<T> class that is empty and has the specified initial capacity or the default initial capacity, whichever is greater.

public ObservableStack(int capacity)

Parameters

capacity int

The initial number of elements that the stack can contain.

Exceptions

ArgumentOutOfRangeException

Thrown when capacity is less than zero.

Properties

Count

Gets the number of elements contained in the stack.

public int Count { get; }

Property Value

int

The number of elements contained in the stack.

Methods

Clear()

Removes all objects from the stack.

public void Clear()

Contains(T)

Determines whether an element is in the stack.

public bool Contains(T item)

Parameters

item T

The object to locate in the stack. The value can be null for reference types.

Returns

bool

True if item is found in the stack; otherwise, false.

CopyTo(T[], int)

Copies the stack to an existing one-dimensional System.Array, starting at the specified array index.

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

Parameters

array T[]

The one-dimensional System.Array that is the destination of the elements copied from stack. The System.Array must have zero-based indexing.

arrayIndex int

The zero-based index in array at which copying begins.

Exceptions

ArgumentNullException

Thrown when array is null.

ArgumentOutOfRangeException

Thrown when arrayIndex is less than zero.

ArgumentException

The number of elements in the source stack is greater than the available space from arrayIndex to the end of the destination array.

GetEnumerator()

Returns an enumerator for the stack.

public Stack<T>.Enumerator GetEnumerator()

Returns

Stack<T>.Enumerator

An System.Collections.Generic.Stack`1.Enumerator for the stack.

Peek()

Returns the object at the top of the stack without removing it.

public T Peek()

Returns

T

The object at the top of the stack.

Exceptions

InvalidOperationException

Thrown when stack is empty.

Pop()

Removes and returns the object at the top of the stack.

public T Pop()

Returns

T

The object removed from the top of the stack.

Exceptions

InvalidOperationException

Thrown when stack is empty.

Push(T)

Inserts an object at the top of the stack.

public void Push(T item)

Parameters

item T

The object to push onto the stack. The value can be null for reference types.

ToArray()

Copies the stack to a new array.

public T[] ToArray()

Returns

T[]

A new array containing copies of the elements of the stack.

TrimExcess()

Sets the capacity to the actual number of elements in the stack, if that number is less than 90 percent of current capacity.

public void TrimExcess()

Events

CollectionChanged

Occurs when the stack changed.

public event NotifyCollectionChangedEventHandler CollectionChanged

Event Type

NotifyCollectionChangedEventHandler