我试图弄清楚如何动态创建一个具有未知数量密钥的字典。
model = new RecruiterMetricsViewModel() {
RecruiterMetrics = recMetrics,
TableData = recMetrics.SelectToListOrEmpty(r => {
return new TableRowViewModel {
Id = r.Recruit.Id,
Class = "",
Data = new Dictionary < string, string > {
{
"Name", r.Recruit.FirstName + r.Recruit.LastName
},
/* Here i would like to start a foreach if i could. Making the key
equal to an item in my object. And making the value a different
item in my object */
},
};
})
};
型号:
public class RecruiterMetricsViewModel : ListPageViewModel
{
public List<RecruiterMetricsModel> RecruiterMetrics { get; set; }
}
public class RecruiterMetricsModel
{
public RecruiterRecruitingPerformance Recruit { get; set; }
public RecruitingPerformance DailyMetrics { get; set; }
}
我想让密钥等于DailMetrics.Date
,值等于DailMetrics.Average
。