开发者

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜