There is no built-in support for this in C#. You can pass by reference an individual element in an array, but not an address of an array segment that could then be interpreted as a 0-based array in managed code.
The obvious solution is to pass an offset and length along with the array. You can make this a bit less painful by wrapping the array in an IReadOnlyList<T> implementation that encapsulates that for you. For example:
class SubsetList<T> : IReadOnlyList<T>
{
private readonly IReadOnlyList<T> _list;
private readonly int _offset = offset;
private readonly int _length = length;
public SubsetList(IReadOnlyList<T> list, int offset, int length)
{
_list = list;
_offset = offset;
_length = length;
}
public int Count { get { return _length; } }
public T this[int index]
{
get { return _list[offset + index]; }
}
public IEnumerator<T> GetEnumerator()
{
for (int i = _offset; i < _offset + _length; i++)
{
yield return _list[i];
}
}
private IEnumerator IEnumerable.GetEnumerator()
{
return GetEnumerator();
}
}
Note that the above is not really needed, as it turns out .NET has (and has had since .NET 2.0) the ArraySegment<T> struct, which does the above and more. But prior to .NET 4.0, it seems it didn't implement the features that would make it transparent to use (such as interface implementations and indexers).
So I offer the above as an alternative for those so-constrained. Note that IReadOnlyList<T> is itself new to .NET 4.5, so to use the above with prior versions of .NET, change that to IList<T>, and then implement all of the other members of the interface with a simple throw new NotSupportedException() (except possibly the setter for the indexer).
IEnumerable?