二维数组声明 [英] 2 dimensional array declaration

查看:125
本文介绍了二维数组声明的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以声明一个二维字符串数组吗?

 字符串 [] [] objNames = // 存储名称的字符串数组

objNames =  字符串 [nCount] [Messages.DEF_NAMES]; //  nCount,Messages.DEF_NAMES是int变量 



但是出现错误:

错误1无效的排名说明符:预期的','或']'< path> \ Name.cs 3347 FullNameMultiDimension</path> 



为什么?

任何支持都将得到感谢

在此先感谢

雷加兹

Salam

解决方案

字符串 [,] objNames = objNames = 字符串 [nCount,Messages.DEF_NAMES]; pre>


Can i declare a 2 dimensional string array like:

string[][] objNames = null;                //String array to store name

objNames = new string[nCount][Messages.DEF_NAMES];   //nCount,Messages.DEF_NAMES are int variables



But getting an error:

Error 1 Invalid rank specifier: expected ',' or ']' <path>\Name.cs 3347  FullNameMultidimensional</path>



why??

Any support will be appreaciated

Thanks in advance

Regardz

Salam

This tutorial[^] might be good reading material.

You are declaring the a jagged array but initiating it incorrectly. The quickest solution is to declare the array as multidimensional.

string [,] objNames = new string[nCount, Messages.DEF_NAMES];


Set the dimensions of the array like this:

objNames = new string[nCount,Messages.DEF_NAMES];


这篇关于二维数组声明的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆