用空字符串更新值列表,并在其他字段中保留值

本文关键字:其他 字段 保留 字符串 更新 列表 | 更新日期: 2023-09-27 18:21:07

我有一个格式的列表

FieldName-      DataType-
Date            DateTime
DateString      String
Unit            double
Price           double

我想执行一个操作,如果Date上的工作日不是星期一,那么用空字符串更新DateString,否则保持DateString的值不变。

列表中存在数据。

更新我在DataTable dtGas上应用了聚合函数,如下所示-

var qGas = from x in dtGas.AsEnumerable()
                       group x by new
                       {
                           Date = x.Field<DateTime>("Date"),
                           DateString = x.Field<string>("DateString")
                       } into egroup
                       select new
                       {
                           Date = egroup.Key.Date,
                           DateString = egroup.Key.DateString,
                           Unit = egroup.Sum(r => r.Field<double>("Unit")),
                           Price = egroup.Sum(r => r.Field<double>("Price"))
                       };

现在我需要将这个结果显示到图表中。由于大量的数据值在X轴上重叠。

这就是为什么我需要从DateString中删除一些值,只显示其中的几个值。

用空字符串更新值列表,并在其他字段中保留值

您可以简单地使用这样的条件运算符:-

group x by new
      {
          Date = x.Field<DateTime>("Date"),
          DateString = x.Field<string>("DateString")
       } into egroup
let isMonday = egroup.Key.Date.DayOfWeek.ToString() == "Monday"
select new
      {
          Date = egroup.Key.Date,
          DateString = isMonday ? egroup.Key.DateString : "",
          ..other properties