using System;
using System.IO;
public class Earthquake
{
public string Magnitude { get; set; }
public string Location { get; set; }
public string Latitude { get; set; }
public string Longitude { get; set; }
public string depth { get; set; }
public string date { get; set; }
public string EventID { get; set; }
public string URL { get; set; }
public Earthquake()
: this(string.Empty, string.Empty, string.Empty, string.Empty, string.Empty, string.Empty, string.Empty, string.Empty)
{ }
public Earthquake(string magna, string locate, string lat, string longi, string dept, string dat, string Event, string website)
{
Convert.ToDouble(Magnitude = magna);
Location = locate;
Convert.ToDouble(Latitude = lat);
Convert.ToDouble(Longitude= longi);
Convert.ToDouble(depth = dept);
date = dat;
EventID = Event;
URL = website;
}
}
public class ManageData
{
public void getData()
{
string[] text = File.ReadAllLines(@"Earthquakes.csv");
foreach (string line in text)
{
string[] myColumns = line.Split(',');
Earthquake earth = new Earthquake(myColumns[0], myColumns[1], myColumns[2], myColumns[3], myColumns[4], myColumns[5], myColumns[6], myColumns[7]);
//here i want to put each data in the Earthquake class
}
}
}
本质上 csv 文件是 8 列,所以我所做的就是逐行读取文件,然后创建一个数组来存储以逗号分隔的字符串中的每条数据。我现在要做的是对数据进行排序,首先按幅度,然后使用冒泡排序按深度。