Reputation: 6823
I have a service which returns a custom object like this:
public List<Image> Images { get; set; }
The image class is like the following:
public string Url { get; set; }
public string MobilelOverride { get; set; }
public string AltText { get; set; }
public string Attribution { get; set; }
public int? Width { get; set; }
public int? Height { get; set; }
In our view model, I have an array of strings.
public List<String> ProductImageUrls { get; set; }
I am not sure how to convert the List of images into a list of the Image.Url
for the ProductImageUrls
array.
Upvotes: 1
Views: 167
Reputation: 1422
What you want to do is to SELECT
the Url
property of each Image
, and place it into a List
of String
(because Url is a String
).
It is pretty easy using Linq :
ProductImageUrls = Images.Select(a => a.Url).ToList();
Upvotes: 2