Visual C#从文件中读取。 [英] Visual C# reading from file.

查看:108
本文介绍了Visual C#从文件中读取。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用VS 2017 C#窗体。我有一个2D数组:

I'm using VS 2017 C# windows forms.I have a 2D array:

string [,] bigData = new string [32,25];

string[,] bigData = new string[32,25];

我正在尝试读取数组的值格式:

I'm trying to read value form txt for the array:

(bigdata.txt用数字填充)

(the bigdata.txt is filled with numbers)

读完数组后,有些东西坏了。

something is bad,after reading the array is full of 0.

有什么问题?

推荐答案

嗨大约翰尼,

感谢您发布此处。

对于您的问题,您可以尝试以下代码从文件中读取数据并将其保存到2D数组。

For your question, you could try the code below to read data from file and save it to 2D array.

string[,] bigData = new string[32, 25];

            // I'm trying to read value form txt for the array:

            var input = File.ReadAllLines("bigData.txt");

            foreach (var row in input)
            {
                var s = row.Split(' ');
                for (int i = 0; i < bigData.GetLength(0); i++)
                {
                    for (int j = 0; j < bigData.GetLength(1); j++)
                    {
                        bigData[i, j] = s[j];
                    }
                }
            }

我的.txt文件。




最好的问候,

Wendy


这篇关于Visual C#从文件中读取。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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