以下代码利用ArrarSegment泛型结构,从int数组arr中取出arr[2]到arr[5]
代码语言:javascript复制using System;
using System.Collections;
class Program
{
static void Main(string[] args)
{
int[] arr = { 1, 2, 3, 4, 5, 6, 7, 8 };
ArraySegment<int> segment = new ArraySegment<int>(arr, 2, 3);
for (int i = segment.Offset; i < segment.Offset segment.Count; i )
{
Console.WriteLine(segment.Array[i]);
}
Console.Read();
}
}
运行结果:
3
4
5