Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/list/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何将字符串列表强制转换为自定义数据类型?_C#_List_Csv_Types - Fatal编程技术网

C# 如何将字符串列表强制转换为自定义数据类型?

C# 如何将字符串列表强制转换为自定义数据类型?,c#,list,csv,types,C#,List,Csv,Types,背景:我试图从一个包含字符串和双精度字符的csv文件中读取数据。我想让字符串保持原样,用于搜索和索引目的,但能够对列表中的双精度值执行数据分析。我也不想在将整个csv文件分为不同类别之前将其读取到内存中,因此我尝试将其分配到一个列表中,其中包含从csv读取的自定义数据类型 如何将单个列表项转换为双精度,然后将其添加到列表中 class data { public List<string> timefrom { get; set; } public List<st

背景:我试图从一个包含字符串和双精度字符的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++;

        }

    }
类数据
{
公共列表时间从{get;set;}
公共列表timeto{get;set;}
公共列表类型{get;set;}
公共列表站点{get;set;}
公共列表框{get;set;}
公共列表组{get;set;}
公共列表sourcecopy{get;set;}
公共列表destcopy{get;set;}
公共列表gridid{get;set;}
公共列表stat{get;set;}
公共列表值{get;set;}
公共列表单元{get;set;}
公共列表峰值{get;set;}
}
一班
{
公开名单
WANtpfromSite,
WANtpbyCG,
以CG的名义收入,
LinkUtilbyCG,
BoxUtil,
压缩CPU,
复制CPU,
压缩比,
重复数据消除比率,
IncomingWritesbyBox,
IncomingWritesbyBoxReplicating,
邮箱,
IObyBoxReplicating,
包裹丢失,
线路延迟;
public void getDayData(字符串目录)
{
字符串[]文件项;
fileEntries=System.IO.Directory.GetFiles(Directory+“/home/www/info/long_term_stats”);
字符串filePath=fileEntries[0];
System.IO.StreamReader sr=新的System.IO.StreamReader(文件路径);
列表行;
int行=1;
而(!sr.EndOfStream)
{
//将读取的行拆分为字符串值列表
Line=sr.ReadLine().Split(',').ToList();
//在这里,我可能会使用switch case来设置变量,但这是它应该做的一个示例。
if(第[8]行)=“站点的广域网吞吐量”)
{
//这里是我遇到的问题-它不能隐式地将字符串列表转换为数据列表,因为
//列表中的单个双精度值。我如何明确地转换“行”
//变量转换为类型?
WANtpfromSite=列表<数据>数据类型;
}
行++;
}
}

好吧-我越是关注一组数据表元素,我就越需要它。我不做列表,而是为每个变量类型设置一个数据表。

如果有一种数据类型可以实现这一点,或者有一个我不知道的免费库,请告诉我!我对C#相当陌生(我对MATLAB和所有它可以轻松转换数据类型的东西都很感兴趣——所以这种问题对我来说是新问题)