Enhanced C#
Language of your choice: library documentation
|
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...
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] |
T | First [get] |
T | Last [get] |
T | this[int index] [get, set] |
T | 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 > | |
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) | |
T | PopFirst (out bool fail) |
T | 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 () |
T | 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) |
|
inline |
Initializes a slice.
ArgumentException | The start index was below zero. |
The (start, count) range is allowed to be invalid, as long as 'start' and 'count' are zero or above.
list.Count - start
. Note that the Count of the slice will not increase if the list expands after the slice is created.
|
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).
ArgumentNullException | array is null. |
ArgumentOutOfRangeException | arrayIndex is negative. |
ArgumentException | The 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 >.
|
get |
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.