您好,欢迎访问一九零五行业门户网

如何在C#中访问数组元素?

first, define and initalize an array −
int[] p = new int[3] {99, 92, 95};
现在,显示数组元素 −
for (j = 0; j < 3; j++ ) { console.writeline("price of product[{0}] = {1}", j, p[j]);}
要访问任何元素,只需像这样包含所需元素的索引 −
p[2];
上述是访问第三个元素的方法。
现在让我们看完整的代码 −
示例using system;namespace program { class demo { static void main(string[] args) { int[] p = new int[3] {99, 92, 95}; int j; for (j = 0; j < 3; j++ ) { console.writeline("price of product[{0}] = {1}", j, p[j]); } // access int e = p[2]; console.writeline("product 3rd price: "+e); console.readkey(); } }}
以上就是如何在c#中访问数组元素?的详细内容。
其它类似信息

推荐信息