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.IArraySink< T > Loyc.Collections.IListSource< T > Loyc.Collections.IIsEmpty Loyc.Collections.IAddRange< T > Loyc.Collections.ICollectionImpl< T > Loyc.Collections.ICollectionAndSource< T > Loyc.Collections.IListSource< T > Loyc.Collections.IListAndReadOnly< 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.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.IArraySink< 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)
 Copies the elements of the collection to an Array, starting at a particular array index. More...
 
bool Remove (T item)
 
bool TrySet (int index, T value)
 
void AddRange (IReadOnlyCollection< T > list)
 
void AddRange (IEnumerable< T > list)
 
- Public Member Functions inherited from Loyc.Collections.IListSource< T >
IRange< T > Slice (int start, int count=int.MaxValue)
 Returns a sub-range of this list. More...
 
- Public Member Functions inherited from Loyc.Collections.IContains< T >
bool Contains (T item)
 Returns true if and only if the collection contains the specified item. More...
 
- Public Member Functions inherited from Loyc.Collections.ICollectionSink< T >
void Clear ()
 
bool Remove (T item)
 
- Public Member Functions inherited from Loyc.Collections.IAddRange< T >
void AddRange (IEnumerable< T > e)
 
void AddRange (IReadOnlyCollection< T > s)
 

Constructor & Destructor Documentation

◆ ListSlice()

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

◆ CopyTo()

void Loyc.Collections.ListSlice< T >.CopyTo ( T[]  array,
int  arrayIndex 
)
inline

Copies the elements of the collection to an Array, starting at a particular array index.

It's usually more convenient to call the ToArray() extension method, which calls this method for you.

This method exists for performance reasons (the collection itself can often copy data out faster than an enumerator can).

Exceptions
ArgumentNullExceptionarray is null.
ArgumentOutOfRangeExceptionarrayIndex is negative.
ArgumentExceptionThe number of elements in the source collection is greater than the available space from arrayIndex to the end of the destination array.

Implements Loyc.Collections.ICollectionSource< T >.

Property Documentation

◆ InternalList

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.