访问数组与索引数组 [英] Access Array with an Array of Indices
本文介绍了访问数组与索引数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在想,如果有可能使用数组,而不是多个整数访问多维数组的特定元素。
I wondered, if it was possible to access a specific element of a multidimensional array using an array, rather than multiple integers.
例如像:
int[,] map = sampleMap;
int[] position = { 1, 2 };
sampleObject = map[position]; // This line won't work. "cannot implicitly convert type 'int[]' to 'int'"
而不是:
sampleObject = map[position[1], position[2]]
当然,只有2个维度时,它不会是太大的问题,但是想象一下,我有很多方面,像10:
Of course, when working with only 2 dimensions, it wouldn't be much of a problem, but imagine I had many dimensions, like 10:
map[position[1], position[2], position[3], ..., position[10]]
这将是更漂亮,更优雅,只写:
It would be much nicer and more elegant, to just write:
map[position]
我一直在四处寻找,但我发现最好的是如何访问数组中的[在此插入语言编程]或如何访问元素从[插入数组类型在这里]或类似的东西。
I've been looking around, but the best I found was "How to access Arrays in [insert programming language here]" or "how to access elements from [insert Array type here]" or things like that.
推荐答案
这篇关于访问数组与索引数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文