Enhanced C#
Language of your choice: library documentation
Properties | Public Member Functions | List of all members
Loyc.Collections.INegListSource< out out 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< out out 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 <= 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< out out T >.Slice ( int  start,
int  count = int.MaxValue 
)

Returns a sub-range of this list.

Referenced by Loyc.Syntax.LNode.MergeBinary(), and Loyc.Collections.NegListSlice< T >.NegListSlice().

T Loyc.Collections.INegListSource< out out 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);

Referenced by Loyc.Syntax.LNode.MergeBinary().

Property Documentation

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

Returns the maximum valid index in the collection.

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

Referenced by Loyc.Syntax.LNode.Equals(), Loyc.Syntax.LNodeExt.GetCaptureIdentifier(), Loyc.Collections.NegListSlice< T >.NegListSlice(), and Loyc.Syntax.LNodeExt.ToLNode().

int Loyc.Collections.INegListSource< out out T >.Min
get
T Loyc.Collections.INegListSource< out out 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.