所以我试图读取一个 csv 文件,它本质上是一个由单词分隔的数据列表,而我到目前为止所做的是使用 ReadAllLines ,然后从那里用 text.Split(','); 分隔。唯一的问题是我只是阅读了这种列表/数组类方法,而不是创建一个实际的数组,所以我不知道如何调用它或使用它。这是我到目前为止所拥有的:
using System;
using System.IO;
public class Earthquake
{
public double Magnitude { get; set; }
public string Location { get; set; }
public double Latitude { get; set; }
public double Longitude { get; set; }
public double depth { get; set; }
public string date { get; set; }
public string EventID { get; set; }
public string URL { get; set; }
public Earthquake(double magna, string locate, double lat, double longi, double dept, string dat, string Event, string website)
{
Magnitude = magna;
Location = locate;
Latitude = lat;
Longitude= longi;
depth = dept;
date = dat;
EventID = Event;
URL = website;
}
}
public class ManageData
{
public int count;
public void getData()
{
string[] text = File.ReadAllLines(@"Earthquakes.csv");
foreach (string word in text[count].Split(','))
{
//here i want to put each data in the Earthquake class
}
}
}