More elegant way to create an array, where each element is the index
Is there more elegant way(LINQ 开发者_JAVA技巧or other) to initialize array like this?
int[] result = new int[PageCount];
for (int i = 0; i < PageCount; i++)
{
result[i] = i;
}
return result;
I'd use:
int[] result = Enumerable.Range(0, PageCount).ToArray();
It's not the speediest solution possible, but it's unlikely to be a bottleneck in most apps.
精彩评论