0

背景:我正在尝试从包含字符串和双打混合的 csv 文件中读取。我想保留字符串以用于搜索和索引目的,但能够对列表中的双精度值执行数据分析。我也不想在将整个 csv 文件分成不同的类别之前将其读入内存,因此我尝试将其分配给具有自定义数据类型的列表,因为它是从 csv 读取的。

如何将该单个列表条目转换为双精度然后将其添加到列表中?

class data
{
    public List<string> timefrom { get; set; }
    public List<string> timeto { get; set; }
    public List<string> type { get; set; }        
    public List<string> site { get; set; }
    public List<string> box { get; set; }
    public List<string> group { get; set; }        
    public List<string> sourcecopy { get; set; }
    public List<string> destcopy { get; set; }
    public List<string> gridid { get; set; }        
    public List<string> stat { get; set; }
    public List<double> value { get; set; }
    public List<string> unit { get; set; }
    public List<string> peak { get; set; }
}

class Class1
{
    public List<data> 
        WANtpfromSite, 
        WANtpbyCG, 
        IncomingWritesbyCG, 
        LinkUtilbyCG, 
        BoxUtil, 
        CompressionCPU, 
        ReplicationCPU, 
        CompressionRatio, 
        DeduplicationRatio, 
        IncomingWritesbyBox, 
        IncomingWritesbyBoxReplicating, 
        IObyBox, 
        IObyBoxReplicating, 
        PacketLoss, 
        LineLatency;


    public void getDayData(string directory)
    {

        string[] fileEntries;

        fileEntries = System.IO.Directory.GetFiles(directory + "/home/www/info/long_term_stats");
        string filePath = fileEntries[0];
        System.IO.StreamReader sr = new System.IO.StreamReader(filePath);
        List<string> Line;
        int row = 1;
        while (!sr.EndOfStream)
        {
            //Splits the line read into a list of string values
            Line = sr.ReadLine().Split(',').ToList<string>();

            // Here I'll probably use a switch case to set the variable, but this is an example of what it should do.
            if (Line[8] == "Wan Throughput from site")
            {
                //Here is where I'm having the problem - it can't implicitely convert the string list to a data list because
                // of that single double value within the list.  How would I go about explicitely converting the "Line" 
                //variable to a <data> type?

                WANtpfromSite = List < data > datatype;
            }
            row++;

        }

    }
4

1 回答 1

0

好吧 - 我越看越透彻,我需要的是一组 DataTable 元素。我没有做一个列表列表,而是为每个变量类型设置了一个数据表。

于 2013-10-18T00:34:24.760 回答