你可以使用StreamReader类来读取txt文件的每一行数据。以下是示例代码:

using System;
using System.IO;

class Program
{
    static void Main(string[] args)
    {
        string filePath = "path/to/your/file.txt";

        // 使用StreamReader打开文件
        using (StreamReader sr = new StreamReader(filePath))
        {
            string line;

            // 逐行读取文件内容
            while ((line = sr.ReadLine()) != null)
            {
                Console.WriteLine(line);
            }
        }
    }
}

你只需要将filePath替换为你的txt文件的路径即可。这段代码将逐行读取文件并将每一行打印到控制台上。

C#读取TXT每一行数据

原文地址: https://www.cveoy.top/t/topic/i5Y2 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录