我想在以下词典中获取列表中的项目总数:
Dictionary<int,List<string>> dd = new Dictionary<int,List<string>>() { {1,new List<string> {"cem"}},{2,new List<string> {"cem","canan"}},{3,new List<string> {"canan","cenk","cem"}} }; // This only returns an enumerated array. var i = (from c in dd select c.Value.Count).Select(p=>p);
解决方法
我相信这会让你有效而清晰地获得你想要的数量.在引擎盖下它必须遍历列表,但要获得总计数,没有办法避免这种情况.
var i = dd.Values.Sum(x => x.Count);