Enhanced C#
Language of your choice: library documentation

Documentation moved to ecsharp.net

GitHub doesn't support HTTP redirects, so you'll be redirected in 3 seconds.

 All Classes Namespaces Functions Variables Enumerations Enumerator Properties Events Pages
Properties | Public Member Functions | List of all members
Loyc.Collections.INegListSource< T > Interface Template Reference

This interface is the counterpart to IListSource{T} for lists whose minimum index is not (necessarily) zero. More...


Source file:
Inheritance diagram for Loyc.Collections.INegListSource< T >:
Loyc.Collections.INegArray< T > Loyc.Collections.NegListSlice< T > Loyc.Collections.NegListSource< T > Loyc.Collections.INegAutoSizeArray< T > Loyc.Collections.INegDeque< T > Loyc.Collections.NegList< T >

Remarks

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:

for (int i = list.Min; i &lt;= list.Max; i++) { ... }

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...
 
this[int index] [get]
 Gets the item at the specified index. More...
 

Public Member Functions

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...
 

Member Function Documentation

IRange<T> Loyc.Collections.INegListSource< T >.Slice ( int  start,
int  count = int.MaxValue 
)
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.

Parameters
indexAn index in the range Min to Max.
failA flag that is set on failure. To improve performance slightly, this flag is not cleared on success.
Returns
The element at the specified index, or default(T) if the index is not valid.

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:

bool TryGet(int index, ref T value);
T TryGet(int, T defaultValue);

Implemented in Loyc.Collections.NegListSlice< T >, Loyc.Collections.NegListSource< T >, and Loyc.Collections.NegList< T >.

Property Documentation

int Loyc.Collections.INegListSource< T >.Max
get

Returns the maximum valid index in the collection.

Count must equal Max-Min+1. If Count is 0, Max = Min-1

int Loyc.Collections.INegListSource< T >.Min
get

Returns the minimum valid index in the collection.

Referenced by Loyc.Collections.NegListSlice< T >.NegListSlice().

T Loyc.Collections.INegListSource< T >.this[int index]
get

Gets the item at the specified index.

Parameters
indexAn index in the range Min to Max.
Exceptions
ArgumentOutOfRangeExceptionThe index provided is not valid in this list.
Returns
The element at the specified index.