【发布时间】:2013-05-05 09:22:06
【问题描述】:
C#中数组索引的类型是什么?
例如,在下面的代码中,索引是否会在访问数组元素(第三行)之前转换为 int?
T[] myArray = new T[255];
byte index = 2;
T element = myArray[index];
如果不是,使用 'byte' 类型的索引访问数组元素是否比使用 'int' 类型的索引更快?
谢谢
【问题讨论】:
-
我很惊讶这个问题似乎以前没有被问过 C#。为了完整起见,在 C++ (stackoverflow.com/q/8111357/96780) 和“C99” (stackoverflow.com/questions/3174850/type-for-array-index-in-c99) 中提及它的对应物可能会很有趣。
标签: c# arrays indexing int byte