Enhanced C#
Language of your choice: library documentation
Public fields | Public static fields | Properties | Public Member Functions | List of all members
Loyc.Collections.ListSlice< T > Struct Template Reference

Adapter: a wrapper of a list that provides a view of a range of elements. Objects of this type are returned from ListExt.Slice<T> More...


Source file:
Inheritance diagram for Loyc.Collections.ListSlice< T >:
Loyc.Collections.IRange< T > Loyc.Collections.IListAndListSource< T > Loyc.Collections.ICollectionEx< T > Loyc.Collections.IArray< T > Loyc.Collections.IIsEmpty Loyc.Collections.ISinkArray< T > Loyc.Collections.IListSource< T > Loyc.Collections.IIsEmpty Loyc.Collections.IAddRange< T > Loyc.Collections.ISinkCollection< T > Loyc.Collections.ICollectionAndReadOnly< T > Loyc.Collections.ICollectionAndReadOnly< T > Loyc.Collections.IListSource< T >

Remarks

Adapter: a wrapper of a list that provides a view of a range of elements. Objects of this type are returned from ListExt.Slice<T>

ListSlice provides both a IList<T> interface and a IRange<T> interface, and it is important not to confuse them. The IList<T> interface allows you to insert and remove items from both the original list and the slice simultaneously. The IRange<T> interface allows you to "Pop" items from the front and back, but this reduces the length of the slice only, not the original list.

Public fields

IList< T > _list
 
int _start
 
int _count
 

Public static fields

static readonly ListSlice< T > Empty = new ListSlice<T>()
 

Properties

int Count [get]
 
bool IsEmpty [get]
 
First [get]
 
Last [get]
 
this[int index] [get, set]
 
this[int index, T defaultValue] [get]
 
IList< T > InternalList [get]
 Returns the original list. More...
 
int InternalStart [get]
 
int InternalStop [get]
 
bool IsReadOnly [get]
 
- Properties inherited from Loyc.Collections.ICount
int Count [get]
 Gets the number of items in the collection. More...
 
- Properties inherited from Loyc.Collections.IIsEmpty
bool IsEmpty [get]
 
- Properties inherited from Loyc.Collections.IArray< T >
new T this[int index] [get, set]
 Gets or sets an element of the array-like collection. More...
 
- Properties inherited from Loyc.Collections.ISinkArray< T >
this[int index] [set]
 

Public Member Functions

 ListSlice (IList< T > list, int start, int count=int.MaxValue)
 Initializes a slice. More...
 
 ListSlice (IList< T > list)
 
PopFirst (out bool fail)
 
PopLast (out bool fail)
 
IFRange< T > ICloneable< IFRange< T > >. Clone ()
 
IBRange< T > ICloneable< IBRange< T > >. Clone ()
 
IRange< T > ICloneable< IRange< T > >. Clone ()
 
ListSlice< T > ICloneable< ListSlice< T > >. Clone ()
 
IEnumerator< T > IEnumerable< T >. GetEnumerator ()
 
System.Collections.IEnumerator System.Collections.IEnumerable. GetEnumerator ()
 
RangeEnumerator< ListSlice< T >, T > GetEnumerator ()
 
TryGet (int index, out bool fail)
 
IRange< T > IListSource< T >. Slice (int start, int count)
 
ListSlice< T > Slice (int start, int count=int.MaxValue)
 
int IndexOf (T item)
 
void Insert (int index, T item)
 
void RemoveAt (int index)
 
void Add (T item)
 
void Clear ()
 
bool Contains (T item)
 
void CopyTo (T[] array, int arrayIndex)
 
bool Remove (T item)
 
bool TrySet (int index, T value)
 
void AddRange (IReadOnlyCollection< T > list)
 
void AddRange (IEnumerable< T > list)
 
int RemoveAll (Predicate< T > match)
 Removes the all the elements that match the conditions defined by the specified predicate. More...
 
- Public Member Functions inherited from Loyc.Collections.IListSource< T >
TryGet (int index, out bool fail)
 Gets the item at the specified index, and does not throw an exception on failure. More...
 
IRange< T > Slice (int start, int count=int.MaxValue)
 Returns a sub-range of this list. More...
 
- Public Member Functions inherited from Loyc.Collections.IAdd< T >
void Add (T item)
 

Constructor & Destructor Documentation

Loyc.Collections.ListSlice< T >.ListSlice ( IList< T >  list,
int  start,
int  count = int.MaxValue 
)
inline

Initializes a slice.

Exceptions
ArgumentExceptionThe start index was below zero.

The (start, count) range is allowed to be invalid, as long as 'start' and 'count' are zero or above.

  • If 'start' is above the original Count, the Count of the new slice is set to zero.
  • if (start + count) is above the original Count, the Count of the new slice is reduced to list.Count - start. Note that the Count of the slice will not increase if the list expands after the slice is created.

Member Function Documentation

int Loyc.Collections.ListSlice< T >.RemoveAll ( Predicate< T >  match)
inline

Removes the all the elements that match the conditions defined by the specified predicate.

Parameters
matchA delegate that defines the conditions of the elements to remove
Returns
The number of elements removed.

Implements Loyc.Collections.ICollectionEx< T >.

Property Documentation

Returns the original list.

Ideally, to protect the list there would be no way to access its contents beyond the boundaries of the slice. However, the reality in .NET today is that many methods accept "slices" in the form of a triple (list, start index, count). In order to call such an old-style API using a slice, one must be able to extract the internal list and start index values.