利用Dynamic,需要.net4.0以上的支持

 var dg = rel.ResultDocuments.FirstOrDefault()["dg"].AsBsonArray.GroupBy(e=>e);
 dynamic dgobj = new System.Dynamic.ExpandoObject();
 foreach (var cl in dg)
 {
    var count= rel.ResultDocuments.FirstOrDefault()["dg"].AsBsonArray.Count(e => e.Equals(BsonValue.Create(cl.Key)));
   (dgobj as System.Collections.Generic.ICollection<System.Collections.Generic.KeyValuePair<int, int>>).Add(new System.Collections.Generic.KeyValuePair<int, int>(cl.Key.AsInt32, count));
 }

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-01-15
  • 2021-09-25
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-07-22
相关资源
相似解决方案