基于时间

时间:2016-09-08 15:14:12

标签: c#

我有一个如下所示的配置列表,

public class Config
{
    public string CMasterName { get; set; }
    public string cChildName { get; set; }
    public int Hours { get; set; }
}

 List<Config> config = new List<Config>(){
        new Config { CMasterName ="MasterName1", cChildName="ChildName1", Hours=5}
        };

&#34; 5&#34; hrs group for&#34; MasterName1&#34; &安培; &#34; ChildName1&#34;

现在我的PointData列表包含以下数据,

public class PointData
{
    public int DataId { get; set; }
    public string DataDescription { get; set; }
    public DateTime InsertDateTime { get; set; }
    public string MasterName { get; set; }
    public string ChildName { get; set; }
}

 List<PointData> pointData = new List<PointData>(){
        new PointData { DataId = 1, DataDescription="Desc 1", InsertDateTime = new DateTime(2016, 9, 8, 7, 10, 24), MasterName ="MasterName1", ChildName="ChildName1"},
        new PointData { DataId = 2, DataDescription="Desc 2", InsertDateTime = new DateTime(2016, 9, 8, 8, 10, 24), MasterName ="MasterName1", ChildName="ChildName1"},
        new PointData { DataId = 3, DataDescription="Desc 3", InsertDateTime = new DateTime(2016, 9, 8, 10, 10, 24), MasterName ="MasterName1", ChildName="ChildName1"},
        new PointData { DataId = 4, DataDescription="Desc 1", InsertDateTime = new DateTime(2016, 9, 8, 14, 10, 24), MasterName ="MasterName1", ChildName="ChildName1"}
        };

这里,前3个数据点在5小时的时间范围内,#34; MasterName1&#34; &安培; &#34; ChildName1&#34;最后的数据点超过5小时

现在我要匹配&#34; datapoints&#34;列表&#34; config&#34;以这样的方式列出&#34;数据点&#34;的前三个记录将转换为&#34; datapoints&#34;的第1条记录和第4条记录将是一个单独的记录。

请建议!!!

结果应该是一个列表,其中包含一列&#34; count&#34;,如下所示, enter image description here

1 个答案:

答案 0 :(得分:0)

DateTime lowDate = pointData.First().InsertDate;
foreach(PointData pD in pointdata)
        {
            DateTime test = pD.InsertDate;
            List<PointData> subList = pointData.Where(p => p.InsertDate > lowDate && <= test.AddHours(5));
        }