简体   繁体   English

如何访问列表中对象的属性?

[英]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? 有人可以帮我吗?

尝试这个:

typeOfImage = myImages.Select(image => image.AnyPropertyYouNeed).ToList();
if (myImages.Count < 0)
   typeOfImage.Add(myImage[0].GetType().ToString());

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM