Enhanced C#
Language of your choice: library documentation
|
This interface is the counterpart to IListSource{T} for lists whose minimum index is not (necessarily) zero. More...
This interface is the counterpart to IListSource{T} for lists whose minimum index is not (necessarily) zero.
Be careful not to write a loop that relies on ICount.Count or starts at zero! You must always loop from Min to Max, like so:
Properties | |
int | Min [get] |
Returns the minimum valid index in the collection. More... | |
int | Max [get] |
Returns the maximum valid index in the collection. More... | |
T | this[int index] [get] |
Gets the item at the specified index. More... | |
Public Member Functions | |
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... | |
IRange<T> Loyc.Collections.INegListSource< T >.Slice | ( | int | start, |
int | count = int.MaxValue |
||
) |
Returns a sub-range of this list.
Implemented in Loyc.Collections.NegListSlice< T >, Loyc.Collections.NegListSlice< T >, Loyc.Collections.NegListSlice< T >, Loyc.Collections.NegList< T >, and Loyc.Collections.NegListSource< T >.
T Loyc.Collections.INegListSource< T >.TryGet | ( | int | index, |
out bool | fail | ||
) |
Gets the item at the specified index, and does not throw an exception on failure.
index | An index in the range Min to Max. |
fail | A flag that is set on failure. To improve performance slightly, this flag is not cleared on success. |
In my original design, the caller could provide a value to return on failure, but this would not allow T to be marked as "out" in C# 4. For the same reason, we cannot have a ref/out T parameter. Instead, the following extension methods are provided:
Implemented in Loyc.Collections.NegListSlice< T >, Loyc.Collections.NegListSource< T >, and Loyc.Collections.NegList< T >.
|
get |
Returns the maximum valid index in the collection.
Count must equal Max-Min+1. If Count is 0, Max = Min-1
|
get |
Returns the minimum valid index in the collection.
Referenced by Loyc.Collections.NegListSlice< T >.NegListSlice().
|
get |
Gets the item at the specified index.
index | An index in the range Min to Max. |
ArgumentOutOfRangeException | The index provided is not valid in this list. |