XYZ as Co X + Co Y + Co Y.
我正在将此数据从此类输入到通用列表中。
public class UTCTime
{
public DateTime UTCBas { get; set; }
public DateTime UTCSon { get; set; }
public TimeSpan Fark { get; set; }
public char Sezon { get; set; }
public UTCTime(string UTCStart , string UTCStop , string Fark , char Sezon)
{
this.UTCBas = Convert.ToDateTime(UTCStart);
this.UTCBas = Convert.ToDateTime(UTCStop);
this.Fark = TimeSpan.Parse(Fark);
this.Sezon = Sezon;
}
public override string ToString()
{
return $"{this.UTCBas.ToString(@"yyy-MM-dd")} - {this.UTCBas.ToString(@"yyy-MM-dd")} - {this.Fark} - {this.Sezon}";
}
}
我想将LINQ查询的结果添加到将从此分类创建的通用列表中。
public static void MTDoldur()
{
MarketTime.Add(new UTCTime("2000-04-01", "2000-10-28", "03:00", 'Y'));
MarketTime.Add(new UTCTime("2000-10-28", "2001-03-31", "02:00", 'K'));
MarketTime.Add(new UTCTime("2001-03-31", "2001-10-27", "03:00", 'Y'));
MarketTime.Add(new UTCTime("2001-10-27", "2002-04-06", "02:00", 'K'));
MarketTime.Add(new UTCTime("2002-04-06", "2002-10-26", "03:00", 'Y'));
MarketTime.Add(new UTCTime("2002-10-26", "2003-04-05", "02:00", 'K'));
MarketTime.Add(new UTCTime("2003-04-05", "2003-10-25", "03:00", 'Y'));
MarketTime.Add(new UTCTime("2003-10-25", "2004-04-03", "02:00", 'K'));
}
我在VAR数据类型中提取查询类型不会失败,但是我无法在屏幕上打印数据并将其分配给变量。 我想将结果传输到通用列表,然后将数据导出到VAR数据类型的变量中。 我无法解决我的问题,我正在等待您的帮助。
public class SonucTime
{
public TimeSpan Fark { get; set; }
public char Sezon { get; set; }
public SonucTime(TimeSpan Fark , char Sezon)
{
this.Fark = Fark;
this.Sezon = Sezon;
}
public override string ToString()
{
return $"Fark : {this.Fark} Sezon : {this.Sezon}";
}
}
答案 0 :(得分:2)
您在UTCTime构造函数中犯了“复制过去”错误- UTCSon 未初始化。
需要修复构造函数:
public UTCTime(string UTCStart , string UTCStop , string Fark , char Sezon)
{
this.UTCBas = Convert.ToDateTime(UTCStart);
this.UTCSon = Convert.ToDateTime(UTCStop); // <----
this.Fark = TimeSpan.Parse(Fark);
this.Sezon = Sezon;
}
并请求数据:
var sonuc = (from m in MarketTime
where xT >= m.UTCBas && xT <= m.UTCSon
select new SonucTime(m.Fark, m.Sezon))
.ToList();
/*
result:
sonuc
Count = 1
[0] [SonucTime]:{Fark : 02:00:00 Sezon : K}
Fark [TimeSpan]:{02:00:00}
Sezon [char]:75 'K'
*/