我想要一个包含动态密钥名称的列表。
我有以下型号:
public class PlaceTime
{
public int Id { get; set; }
public string Place { get; set; }
public DateTime Day { get; set; }
public DateTime TimeFrom { get; set; }
public DateTime TimeTo { get; set; }
public string Name { get; set; }
}
以下数据:
1, NewYork, 1/1/2015, 8:00 AM, 10:00 AM, Matt
2, NewYork, 1/1/2015, 8:00 AM, 10:00 AM, Ann
3, NewYork, 1/1/2015, 12:00 AM, 14:00 AM, Tom
4, NewYork, 1/1/2015, 15:00 AM, 18:00 AM, Matt
结果我想要以下列表:
List<?> dynamicList;
dynamic[0]: Key = "Place", Value = "New York"
dynamic[0]: Key = "Day", Value = "1/1/2015"
dynamic[0]: Key = "8:00 AM - 10:00 AM", Value = "Matt & Ann"
dynamic[1]: Key = "Place", Value = "New York"
dynamic[1]: Key = "Day", Value = "1/1/2015"
dynamic[1]: Key = "12:00 AM - 14:00 AM", Value = "Tom"
dynamic[2]: Key = "Place", Value = "New York"
dynamic[2]: Key = "Day", Value = "1/1/2015"
dynamic[2]: Key = "15:00 AM - 18:00 AM", Value = "Matt"
如何使用动态数量的元素(取决于存储在PlaceTime模型中的TimeFrom / TimeTo组合)创建具有键名的List,具体取决于模型中的值?
答案 0 :(得分:0)