嗨,我是编程新手。我想读取一个文本文件并采取值(string
s)并将string
的每个字符分别存储在array
中。我使用了一个列表从文本文件中获取值。我发现很难将它们移动到array
中,然后在我的程序中使用这些值。如果可能,请找到我的解决方案。提前感谢你。如何将文件从文件列表存储到c中的变量#
public class file_IO
{
string[] letters = new string[] //I would like to store it in this variable
public void File_Reader()
{
string filepath = @"env.txt"; //Variable to hold string
List<string> file_lines = File.ReadAllLines(filepath).ToList();//returns array of strings into List
foreach (string line in file_lines)
{
}
}
}
首先声明一个数组然后在你的'foreach'循环中加入数组 – WhatsThePoint
你想存储每一行吗?或整个文件作为字符数组? –
@WhatsThePoint谢谢你的回复。如何将列表中的值移动到数组中?我对此很新,不知道语法。 – Rahul