字典groupby visitdate和IsChecked属性C#
我在SelectList类中有一个SelectNode类字典:字典groupby visitdate和IsChecked属性C#,c#,dictionary,group-by,C#,Dictionary,Group By,我在SelectList类中有一个SelectNode类字典: public Dictionary<long, SelectNode> Tbl; 在SelectList类中,我想创建按VisitDate分组的字典,该字典只选中property=true 这是我的方法: /// <summary> /// Method filters checkeditems from SelectNode class via SelectList class /
public Dictionary<long, SelectNode> Tbl;
在SelectList类中,我想创建按VisitDate分组的字典,该字典只选中property=true
这是我的方法:
/// <summary>
/// Method filters checkeditems from SelectNode class via SelectList class
/// </summary>
public void GetSelected()
{
foreach (SelectNode sn in this.Buf.Lst.Selected)
{
//Dont know what to put here to generate new dicationary
}
}
//
///方法通过SelectList类从SelectNode类筛选checkeditems
///
public void GetSelected()
{
foreach(在此.Buf.Lst.Selected中选择节点序号)
{
//不知道在这里放些什么来生成新的数据
}
}
long SecdtionId是字典中的键。提前谢谢。假设
VisitDate
中的string
是可解析的,那么下面的LINQ语句应该可以做到这一点
var ordered = this.Buf.Lst.Selected.Where(o=> o.Value.Checked).GroupBy(o => DateTime.Parse(o.Value.VisitDate));
或者,如果您想将它们作为字符串排序
,只需
var ordered = Tbl.Where(o=> o.Value.Checked).GroupBy(o => o.Value.VisitDate);
您需要使用System.Linq添加
使用
语句列表对进行编码。这些字段位于公共类中的私有类在公共类SelectNodethis.Buf.Lst.Selected=对象中有私有类DataRec,它返回SelectList的实例,没有orderby方法。您需要使用System.Linq添加
在.cs
文件的顶部,您试图对该对象执行foreach
,因此它必须是IEnumerable
,允许使用LINQ
谢谢你LIUFA,var ordered=this.Buf.Lst.Selected.Where(o=>o.Checked.GroupBy(o=>o.VisitDate);很好,我如何将var ordered转换为dictionary或list?基本上,在SelectList类中,我希望将dictionary放在最上面,然后在这个方法中,将ordered转换为CheckedDictionary或类似的东西
var ordered = Tbl.Where(o=> o.Value.Checked).GroupBy(o => o.Value.VisitDate);