Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/303.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/linq/3.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# Linq,其中自定义类列表与以小时为单位的两个日期时间值进行比较_C#_Linq_Datetime - Fatal编程技术网

C# Linq,其中自定义类列表与以小时为单位的两个日期时间值进行比较

C# Linq,其中自定义类列表与以小时为单位的两个日期时间值进行比较,c#,linq,datetime,C#,Linq,Datetime,我有一个自定义类的列表,我正试图从该列表中创建一个新列表,在该列表中我需要返回一个以当前年份小时为单位的日期范围。我一直在尝试以下操作,但它返回的列表为零: List<Core.tokenHistory> firstQuery = thl.Where(x => x.Date.Value.DayOfYear * 24 + x.Date.Value.Hour > day.Value.DayOfYear * 24 && x.Date.Value.DayOfYea

我有一个自定义类的列表,我正试图从该列表中创建一个新列表,在该列表中我需要返回一个以当前年份小时为单位的日期范围。我一直在尝试以下操作,但它返回的列表为零:

List<Core.tokenHistory> firstQuery = thl.Where(x =>
x.Date.Value.DayOfYear * 24 + x.Date.Value.Hour > day.Value.DayOfYear * 24 &&
x.Date.Value.DayOfYear * 24 + x.Date.Value.Hour < (day.Value.DayOfYear + 1) * 24)
.ToList(); 

如果您第一次查询的列表跨越多年,那么这是行不通的。我现在正在创建自己的类,其中包含两个整数,一个用于小时,一个用于年度。我真不敢相信我花了一整天才意识到这一点…

你怎么知道它不起作用?你能给我们看一下
CustomClass
的代码吗?我知道代码不起作用,因为firstQuery.Count=0。你如何计算
今天
明天
?哎呀,忘了我在查询之外测试变量了。编辑了这篇文章。
        public class tokenHistory
    {

        DateTime? _date;
        string _action;
        string _recipient;
        int _tokens;
        int _balance;


        public tokenHistory(DateTime? date, string action, string recipient, int tokens, int balance)
        {
            this._date = date;
            this._action = action;
            this._recipient = recipient;
            this._tokens = tokens;
            this._balance = balance;

        }

        public DateTime? Date { get { return _date; } set { _date = value; } }
        public string Action { get { return _action; } set { _action = value; } }
        public string Recipient { get { return _recipient; } set { _recipient = value; } }
        public int Tokens { get { return _tokens; } set { _tokens = value; } }
        public int Balance { get { return _balance; } set { _balance = value; } }
    }