多维数组 - 在编译时不知道维数 [英] Multiple-dimension array - where the number of dimension is not known at compile time
问题描述
我知道要声明一个二维数组我说'int [,] = new int [3,3]"而一个三维数组"int [,,] = new int [3,3,3]"。
I know to declare a two-dimension array I say "int [,] = new int[3,3]" while a three-dimension array "int [,,] = new int[3,3,3]".
如果在编译时不知道维数,只在运行时知道?我如何声明它?
What if the number of dimensions is not know at compile time and only known at run time? How do I declare it?
谢谢!
推荐答案
编写一个可以处理多个的类尺寸数组。写一个索引器操作符,这样你就可以访问类中的元素,就像它是一个多维数组一样,前提是你选择的编程语言有一个类型系统,它可以有类
和索引器操作符。
write a class that can handle multiple dimensions arrays. write an indexer operator so you can access elements in the class as if it were a multiple dimensional array, provided your choice of programming language has a type system capable of having classes and indexer operators.
这篇关于多维数组 - 在编译时不知道维数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!