1

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.

1 Answer 1

2

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();
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.