以下是将CSV文件数据转换为List类的示例代码:

using System;
using System.Collections.Generic;
using System.IO;

class Program
{
    static void Main(string[] args)
    {
        List<string[]> data = new List<string[]>();

        using (var reader = new StreamReader("data.csv"))
        {
            while (!reader.EndOfStream)
            {
                string line = reader.ReadLine();
                string[] values = line.Split(',');
                data.Add(values);
            }
        }

        // 输出List中的数据
        foreach (string[] row in data)
        {
            Console.WriteLine(string.Join(", ", row));
        }
    }
}

在此示例代码中,我们首先创建了一个List<string[]>类型的变量data,用于存储CSV文件中的数据。然后使用StreamReader打开CSV文件,使用Split方法将每一行数据分割成一个字符串数组,最后将该数组添加到List中。最后,我们使用foreach循环遍历List中的数据,并将其输出到控制台上

C#把csv文件数据转换成list类

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

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