在C#中读取数组中的数组 [英] Read words into an array in C#

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

问题描述

我想读取一个列表的数组。我已经阅读了一些教程和其他问题在这个网站,仍然卡住。

I am trying to read a list of words into an array. I have read some tutorials and other questions on this site and am still stuck. It is probably something simple that I am missing but I can't figure it out.

这是我的代码:

string badWordsFilePath = openFileDialog2.FileName.ToString();
                badWords = badWordsFilePath.Split(' ');
                MessageBox.Show("Words have been imported!");
                BadWordsImported = true;

我想要发生的是将文件中的所有单词逐一放入数组错误。

What I want to happen is for all the words in the file to be put one by one into the array badWords.

任何想法我做错了什么?

Any ideas what I am doing wrong?

推荐答案

你需要做的是读取文件。

What you need to do is actually read the file.

string badWordsFilePath = openFileDialog2.FileName;
string fileContents = File.ReadAllText(badWordsFilePath);
badWords = fileContents.Split(' ');

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

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