Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/list/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 从另一个txt列表c中调用txt列表#_C#_List - Fatal编程技术网

C# 从另一个txt列表c中调用txt列表#

C# 从另一个txt列表c中调用txt列表#,c#,list,C#,List,我有六个txt文件。其中一个拿着其他人的名字。例如,我有一个名为brands的txt文件。在品牌的内部有汽车品牌的名称,例如:bmv、丰田、奥迪。。。 还有一些文件的名字完全相同(bmv.txt、toyota.txt、audi.txt)。 (对不起,我的英语不是我的母语) 我的问题是,我可以为使用for loop的每辆车创建数组吗?虽然这个问题很模糊,但我将为您提供一个基本流程,说明您需要做什么 读取每个类别的文件名并存储它们 然后读取每个类别的内容,并将值与文件名匹配 读取每个子类别文件的内

我有六个txt文件。其中一个拿着其他人的名字。例如,我有一个名为brands的txt文件。在品牌的内部有汽车品牌的名称,例如:bmv、丰田、奥迪。。。 还有一些文件的名字完全相同(bmv.txt、toyota.txt、audi.txt)。
(对不起,我的英语不是我的母语)


我的问题是,我可以为使用for loop的每辆车创建数组吗?

虽然这个问题很模糊,但我将为您提供一个基本流程,说明您需要做什么

  • 读取每个类别的文件名并存储它们
  • 然后读取每个类别的内容,并将值与文件名匹配
  • 读取每个子类别文件的内容
  • 您将使用以下代码示例来实现这一点

    获取目录中的文件名:

    string[]fileEntries=Directory.GetFiles(targetDirectory)

    读取文件的内容:

    using (StreamReader sr = new StreamReader("TestFile.txt"))
     {
         string line;
         // Read and display lines from the file until the end of
         // the file is reached.
         while ((line = sr.ReadLine()) != null)
         {
             Console.WriteLine(line);
          }
     }
    
    
    这是一个基本的方法,应该让你开始


    祝你好运。

    欢迎来到StackOverFlow。这不是家庭作业写作服务。请阅读