C# 使用lambda从并发字典中选择记录
我有一个以datetime为键和整数值的并发字典。每半小时就会有一个新条目,我有过去一周的数据,我想选择特定天数的最大整数值。有什么建议吗?类似于:C# 使用lambda从并发字典中选择记录,c#,vb.net,lambda,C#,Vb.net,Lambda,我有一个以datetime为键和整数值的并发字典。每半小时就会有一个新条目,我有过去一周的数据,我想选择特定天数的最大整数值。有什么建议吗?类似于: var value = dictionary.Where(x => x.Key.Day == 5).Max(x=>x.Value); 比如: var value = dictionary.Where(x => x.Key.Day == 5).Max(x=>x.Value); 比如: var value = diction
var value = dictionary.Where(x => x.Key.Day == 5).Max(x=>x.Value);
比如:
var value = dictionary.Where(x => x.Key.Day == 5).Max(x=>x.Value);
比如:
var value = dictionary.Where(x => x.Key.Day == 5).Max(x=>x.Value);
比如:
var value = dictionary.Where(x => x.Key.Day == 5).Max(x=>x.Value);
一种可能性是按日期对并发字典中的值进行分组:
var dic = new ConcurrentDictionary<DateTime, int>();
dic[new DateTime(2015, 4, 5, 7, 0, 1)] = 1;
dic[new DateTime(2015, 4, 5, 7, 0, 2)] = 2;
dic[new DateTime(2015, 4, 5, 7, 0, 3)] = 3;
dic[new DateTime(2015, 4, 6, 7, 0, 1)] = 5;
dic[new DateTime(2015, 4, 6, 7, 0, 2)] = 6;
dic[new DateTime(2015, 4, 6, 7, 0, 3)] = 7;
var searchDay = new DateTime(2015, 4, 5);
// Find the values corresponding to the specified day
var dates = dic.GroupBy(item => item.Key.Date).FirstOrDefault(x => x.Key == searchDay.Date);
if (dates != null)
{
int max = dates.Max(x => x.Value);
// That's the maximum value for the specified day
}
var dic=新的ConcurrentDictionary();
dic[新日期时间(2015,4,5,7,0,1)]=1;
dic[新日期时间(2015,4,5,7,0,2)]=2;
dic[新日期时间(2015,4,5,7,0,3)]=3;
dic[新日期时间(2015,4,6,7,0,1)]=5;
dic[新日期时间(2015,4,6,7,0,2)]=6;
dic[新日期时间(2015,4,6,7,0,3)]=7;
var searchDay=新日期时间(2015年4月5日);
//查找与指定日期对应的值
var dates=dic.GroupBy(item=>item.Key.Date).FirstOrDefault(x=>x.Key==searchDay.Date);
如果(日期!=null)
{
int max=dates.max(x=>x.Value);
//这是指定日期的最大值
}
一种可能性是按日期对并发字典中的值进行分组:
var dic = new ConcurrentDictionary<DateTime, int>();
dic[new DateTime(2015, 4, 5, 7, 0, 1)] = 1;
dic[new DateTime(2015, 4, 5, 7, 0, 2)] = 2;
dic[new DateTime(2015, 4, 5, 7, 0, 3)] = 3;
dic[new DateTime(2015, 4, 6, 7, 0, 1)] = 5;
dic[new DateTime(2015, 4, 6, 7, 0, 2)] = 6;
dic[new DateTime(2015, 4, 6, 7, 0, 3)] = 7;
var searchDay = new DateTime(2015, 4, 5);
// Find the values corresponding to the specified day
var dates = dic.GroupBy(item => item.Key.Date).FirstOrDefault(x => x.Key == searchDay.Date);
if (dates != null)
{
int max = dates.Max(x => x.Value);
// That's the maximum value for the specified day
}
var dic=新的ConcurrentDictionary();
dic[新日期时间(2015,4,5,7,0,1)]=1;
dic[新日期时间(2015,4,5,7,0,2)]=2;
dic[新日期时间(2015,4,5,7,0,3)]=3;
dic[新日期时间(2015,4,6,7,0,1)]=5;
dic[新日期时间(2015,4,6,7,0,2)]=6;
dic[新日期时间(2015,4,6,7,0,3)]=7;
var searchDay=新日期时间(2015年4月5日);
//查找与指定日期对应的值
var dates=dic.GroupBy(item=>item.Key.Date).FirstOrDefault(x=>x.Key==searchDay.Date);
如果(日期!=null)
{
int max=dates.max(x=>x.Value);
//这是指定日期的最大值
}
一种可能性是按日期对并发字典中的值进行分组:
var dic = new ConcurrentDictionary<DateTime, int>();
dic[new DateTime(2015, 4, 5, 7, 0, 1)] = 1;
dic[new DateTime(2015, 4, 5, 7, 0, 2)] = 2;
dic[new DateTime(2015, 4, 5, 7, 0, 3)] = 3;
dic[new DateTime(2015, 4, 6, 7, 0, 1)] = 5;
dic[new DateTime(2015, 4, 6, 7, 0, 2)] = 6;
dic[new DateTime(2015, 4, 6, 7, 0, 3)] = 7;
var searchDay = new DateTime(2015, 4, 5);
// Find the values corresponding to the specified day
var dates = dic.GroupBy(item => item.Key.Date).FirstOrDefault(x => x.Key == searchDay.Date);
if (dates != null)
{
int max = dates.Max(x => x.Value);
// That's the maximum value for the specified day
}
var dic=新的ConcurrentDictionary();
dic[新日期时间(2015,4,5,7,0,1)]=1;
dic[新日期时间(2015,4,5,7,0,2)]=2;
dic[新日期时间(2015,4,5,7,0,3)]=3;
dic[新日期时间(2015,4,6,7,0,1)]=5;
dic[新日期时间(2015,4,6,7,0,2)]=6;
dic[新日期时间(2015,4,6,7,0,3)]=7;
var searchDay=新日期时间(2015年4月5日);
//查找与指定日期对应的值
var dates=dic.GroupBy(item=>item.Key.Date).FirstOrDefault(x=>x.Key==searchDay.Date);
如果(日期!=null)
{
int max=dates.max(x=>x.Value);
//这是指定日期的最大值
}
一种可能性是按日期对并发字典中的值进行分组:
var dic = new ConcurrentDictionary<DateTime, int>();
dic[new DateTime(2015, 4, 5, 7, 0, 1)] = 1;
dic[new DateTime(2015, 4, 5, 7, 0, 2)] = 2;
dic[new DateTime(2015, 4, 5, 7, 0, 3)] = 3;
dic[new DateTime(2015, 4, 6, 7, 0, 1)] = 5;
dic[new DateTime(2015, 4, 6, 7, 0, 2)] = 6;
dic[new DateTime(2015, 4, 6, 7, 0, 3)] = 7;
var searchDay = new DateTime(2015, 4, 5);
// Find the values corresponding to the specified day
var dates = dic.GroupBy(item => item.Key.Date).FirstOrDefault(x => x.Key == searchDay.Date);
if (dates != null)
{
int max = dates.Max(x => x.Value);
// That's the maximum value for the specified day
}
var dic=新的ConcurrentDictionary();
dic[新日期时间(2015,4,5,7,0,1)]=1;
dic[新日期时间(2015,4,5,7,0,2)]=2;
dic[新日期时间(2015,4,5,7,0,3)]=3;
dic[新日期时间(2015,4,6,7,0,1)]=5;
dic[新日期时间(2015,4,6,7,0,2)]=6;
dic[新日期时间(2015,4,6,7,0,3)]=7;
var searchDay=新日期时间(2015年4月5日);
//查找与指定日期对应的值
var dates=dic.GroupBy(item=>item.Key.Date).FirstOrDefault(x=>x.Key==searchDay.Date);
如果(日期!=null)
{
int max=dates.max(x=>x.Value);
//这是指定日期的最大值
}
词典的日期时间键能否包含小时、分钟和秒?是的日期时间键是否包含秒扫描词典的日期时间键是否包含小时、分钟和秒?是的日期时间键是否包含秒扫描词典的日期时间键是否包含小时,分钟和秒?是DateTime包含秒扫描字典的DateTime键包含小时、分钟和秒?是DateTime包含秒