A Coder
A Coder

Reputation: 3056

How to access properties of an object in a list?

I am trying to take properties from a list of types and put them in another list. I am not exactly sure how you iterate through the list of objects to gain access to the properties.

For example:

List<images> myImages = new List<images>();

List<string> typeOfImage = new List<string>();

typeOfImage.Add(myImages.type);

Can someone help me in this?

Upvotes: 0

Views: 74

Answers (2)

ferdyh
ferdyh

Reputation: 1455

if (myImages.Count < 0)
   typeOfImage.Add(myImage[0].GetType().ToString());

Upvotes: 0

petro.sidlovskyy
petro.sidlovskyy

Reputation: 5103

Try this:

typeOfImage = myImages.Select(image => image.AnyPropertyYouNeed).ToList();

Upvotes: 4

Related Questions