How to read a text file and add the data to a int array in C#?

后端 未结 4 1386
深忆病人
深忆病人 2021-01-27 06:13

I\'m trying to read a text file which contains numbers separated by a comma. When I read using File.Readline() I get it to a string[]. I need to conver

4条回答
  •  猫巷女王i
    2021-01-27 06:46

    I think this is what you want to do. Only thing is that your vallArr should be a two dimensional array that can keep all values. Something like var valArr = new Int64[x, y];

            while ((line = sr.ReadLine()) != null)
            {
                string[] values = line.Split(new string[] { " , " }, StringSplitOptions.None);
    
                for (int i = 0; i < values.Length; i++)
                {
                    valArr[LineCount, i] = Int64.Parse(values[i]);
                }
                LineCount++;
            }
    

提交回复
热议问题