C# 无效的秩说明符:应为'';或';]';错误

C# 无效的秩说明符:应为'';或';]';错误,c#,C#,在我提问之前,我阅读了前面的文章。当我运行脚本时,它显示无效的秩说明符:应为“,”或“]”以下代码处的错误。顺便说一句,我尝试了newfloat[8939100]但它仍然显示错误。 以及如何使用hashtable来保存我编写hashtable注释的结果 namespace function { public partial class Form1 : Form { float userscore,itemscore,result;

在我提问之前,我阅读了前面的文章。当我运行脚本时,它显示
无效的秩说明符:应为“,”或“]”
以下代码处的错误。顺便说一句,我尝试了
newfloat[8939100]但它仍然显示错误。
以及如何使用hashtable来保存我编写hashtable注释的结果

namespace function
{
    public partial class Form1 : Form
    {

            float userscore,itemscore,result;
            string lineitem, lineuser;
            float[][] a = new float[89395][100];          //<----the error is here
            float[][] b = new float[1143600][100];        //<----the error is here
            //float[,] c = new float[89395, 100];
            StreamReader fileitem = new StreamReader("c:\\1.txt");
            StreamReader fileuser = new StreamReader("c:\\2.txt");
        public Form1()
        {
            InitializeComponent();

             for (int x = 0; x <= 8939500; x++)
            {
                lineuser = fileuser.ReadLine();
                string[] values = lineuser.Split(' ');
                int userid, factoriduser;
                foreach (string value in values)
                {
                    userid = Convert.ToInt32(values[0]);
                    factoriduser = Convert.ToInt32(values[1]);
                    userscore = Convert.ToSingle(values[2]);
                    a[userid][factoriduser] = userscore;
                }
            }

            for (int y = 0; y <= 114360000; y++)
            {
                lineitem = fileitem.ReadLine();
                string[] valuesi = lineitem.Split(' ');
                int itemid, factoriditem;
                foreach (string value in valuesi)
                {
                    itemid = Convert.ToInt32(valuesi[0]);
                    factoriditem = Convert.ToInt32(valuesi[1]);
                    itemscore = Convert.ToSingle(valuesi[2]);
                    b[itemid][factoriditem] = itemscore;
                }

            }

        }
        public float dotproduct(int userid,int itemid)
        {

            //get the score of 100 from user and item to dotproduct
            float[] u_f = a[userid];
            float[] i_f = b[itemid];

            for (int i = 0; i <u_f.GetLength(1); i++)
            {
                result += u_f[userid] * i_f[itemid];
            }
            return result;

        }

        private void btn_recomm_Click(object sender, EventArgs e)
        {
            if(txtbx_id.Text==null)
            {
                MessageBox.Show("please insert user id");
            }
         if (txtbx_id.Text != null)
          {
           int sc = Convert.ToInt32(txtbx_id.Text);
           if (sc>=0 &&sc<=89395)
            {
              for (int z=0;z<=1143600;z++)
                {
                  dotproduct(sc,z);
                }
               //Hashtable hashtable = new Hashtable(); 
               //put the result in hashtable
               //foreach (DictionaryEntry entry in hashtable)
                 //{
                   //Console.WriteLine("{0}, {1}", entry.Key, entry.Value);
                // }
            }
         }
            if (txtbx_id==null &&txtbx_itemid==null)
            {
                int uid = Convert.ToInt32(txtbx_id.Text);
                int iid = Convert.ToInt32(txtbx_itemid.Text);
                {
                    if (uid>=0 && uid<=89395 && iid>=0 && iid<=1143600)
                    {
                        dotproduct(uid,iid);
                        MessageBox.Show("The Score of user id "+uid+" is "+result);
                    }
                }
            }
        }
名称空间函数
{
公共部分类Form1:Form
{
float userscore、itemscore、result;
字符串行项目,行用户;
float[]a=new float[89395][100];//不能这样声明。必须先声明外部数组,然后声明所有内部数组:

float[][] a = new float[89395][]; 
for(int i = 0; i < 89395; i++)
    a[i] = new float[100];
不能这样声明。必须先声明外部数组,然后声明所有内部数组:

float[][] a = new float[89395][]; 
for(int i = 0; i < 89395; i++)
    a[i] = new float[100];
参考:


参考资料:

您不能创建这样的新二维数组-一次只能创建一个维度。您可以使用VA循环初始化第二个维度,或者使用LINQ:

float[][] a = Enumerable.Range(0, 89395).Select(i=>new float[100]).ToArray();

您不能像这样创建新的二维数组-一次只能创建一个维度。您可以使用VA循环初始化第二个维度,或者使用LINQ:

float[][] a = Enumerable.Range(0, 89395).Select(i=>new float[100]).ToArray();

它不是
float[,]a=new float[x,y]
-它不是
float[,]a=new float[x,y]
-如果我想使用以下格式float[,]……我该怎么办@marcinjuraszekIt你不需要内部数组具有不同的维度(这就是锯齿数组的用途),你应该使用
[,]
,因为它更容易管理(如您所见,初始化)。如果我想使用以下格式float[,]……我应该怎么做@marcinjuraszekIt您不需要内部数组具有不同的维度(锯齿数组就是为了这个),您应该使用
[,]
,因为它更易于管理(如您所见,初始化)。我以前使用过它,但它向我展示了它第------float[]u_f=a[userid]行的“侧[]中的索引数错误,应为'2'”;您还必须修改其他代码以使用多维数组。我以前使用过它,但第------float[]u_f=a[userid]行的“侧[]中的索引数错误,应为'2'”;您还必须修改其他代码以使用多维数组。