如何将列表对象添加到字典

我有以下响应模型

public class GetMediaTypesReponse
{
    public List<Dictionary<string,string>> Mediatypes { get; set; }
}

和以下业务逻辑

public async Task<GetMediaTypesReponse> GetMediaTypes()
{
    GetMediaTypesReponse response = new GetMediaTypesReponse();
    response.Mediatypes = new List<Dictionary<string,string>>();
    IList<Media> medias = await mediaRepository.GetallAsync();

    foreach ()
    {

    }

    return await Task.FromResult(response);
}
  public class Media
    {
        [Key]
        [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
        public Guid MediaId { get; set; } // Using GUID as this table might have historical data without removing of records
        public int MediaTypeId { get; set; } // for future Use like Banner image
        public string ThumbnailImg { get; set; }
        public string Image { get; set; }
        public bool Isactive { get; set; }
        public bool IsHeroImage { get; set; } //Will be displaced first
        public string ImageText { get; set; } //Text to find images
        public string ImageFileName { get; set; } //Uploaded image filename

    }

我需要为每个循环创建一个字典对象  然后将其添加到列表对象中,因为我们不需要将参数传递给字典对象构造函数那里我们没有机会传递     构造函数中的参数。

keke0328 回答:如何将列表对象添加到字典

如果我理解正确,则可以尝试以下方法:

3. Running the Maven test
本文链接:https://www.f2er.com/3154535.html

大家都在问